Have you ever felt that your macro runs surprisingly slowly when changing PageSetup settings, such as the print area, paper orientation, or margins? This slowness is particularly noticeable when using a network printer.
The reason for this lag is that every time VBA changes a print setting, it communicates with the printer driver to verify the information.
In this article, I will explain the Application.PrintCommunication property, an essential technique to dramatically speed up print settings by temporarily turning off this communication.
Why is Changing Print Settings Slow?
When you change properties of the .PageSetup object (e.g., .PrintArea or .Orientation) in Excel VBA, Excel asks the printer driver via the OS if that setting is physically possible for the current printer.
To use an analogy, it is like walking over to the printer to ask, “Is this setting okay?” every single time you change one item. This “round trip” communication causes significant time loss, especially over a network.
Application.PrintCommunication = False is a command that tells VBA: “I will do the verification later, so let me focus on changing the settings for now!”
Completed VBA Code
Below is a sample VBA code that uses the PrintCommunication property to speed up print settings.
Sub FastPageSetup()
' Declare variables
Dim targetSheet As Worksheet
Set targetSheet = ActiveSheet
' Stop screen updating for further speed optimization
Application.ScreenUpdating = False
' --- 1. Temporarily stop communication with the printer ---
Application.PrintCommunication = False
' --- 2. Change print settings in bulk (Processing here is faster) ---
With targetSheet.PageSetup
.PrintArea = "B2:H80"
.Orientation = xlLandscape ' Set paper to landscape
.Zoom = False
.FitToPagesWide = 1 ' Fit to 1 page wide
.FitToPagesTall = 1 ' Fit to 1 page tall
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
End With
' --- 3. Resume communication (IMPORTANT: Must switch back) ---
Application.PrintCommunication = True
' Resume screen updating
Application.ScreenUpdating = True
' --- 4. Check the result in Print Preview ---
targetSheet.PrintPreview
End Sub
Key Points of the Code
1. Turning Communication OFF
Application.PrintCommunication = False
Write this line immediately before starting any processing related to .PageSetup. This stops Excel from querying the printer for subsequent changes, allowing the process to complete instantly in memory.
2. Batching Changes
With targetSheet.PageSetup
.PrintArea = "B2:H80"
.Orientation = xlLandscape
' ... and other settings
End With
While PrintCommunication is False, write all the print settings you want to change, preferably inside a With block. The more items you need to change, the greater the speed benefit you will get from this technique.
3. Turning Communication ON
Application.PrintCommunication = True
This is the most important step. Once you have finished changing all print settings, you must set this property back to True to resume communication with the printer.
If you forget this, the settings may not be correctly reflected in the printer driver, causing unexpected errors or layout issues during preview or actual printing. Remember: “If you turn it OFF, you must turn it ON.”
Summary
If you want to improve the performance of macros that involve print settings, the following three steps are extremely effective:
- Set
Application.PrintCommunication = Falseat the start of the process. - Perform all
PageSetupchanges in a batch. - Return
Application.PrintCommunication = Trueat the end of the process.
This pattern is an almost mandatory optimization technique when automating forms or reports in VBA. If you feel your processing is slow, please try this “magic spell.”
