Fix Excel VBA Page Setup Differences When Running with F5 and F8
Question details
The user needs to understand why an Excel VBA procedure produces different results when run with F5 versus stepped through with F8.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro updates footer or other page setup properties while Application.PrintCommunication is disabled.
- Observed behavior
- The procedure can produce different results during normal execution and line-by-line debugging.
Open the workbook in Excel and press Alt+F11 to inspect the macro in the VBA editor. Identify where it changes Application.PrintCommunication and where it reads or uses PageSetup properties.
Commit page setup changes before using their values
Use this approach when the macro batches footer or page setup changes with PrintCommunication set to False.
When PrintCommunication is False, Excel caches PageSetup commands instead of communicating each change to the printer. Setting it back to True commits the cached commands; stepping through the macro may also introduce delays that expose timing or printer-driver behavior.
In the VBA editor, place Application.PrintCommunication = False before the PageSetup assignments. Apply the required footer and other settings to an explicitly named worksheet, such as Worksheets("Sheet1").PageSetup.
After the last PageSetup assignment, add Application.PrintCommunication = True before reading the updated properties or calling PrintOut or PrintPreview.
Use an On Error handler or cleanup section that sets Application.PrintCommunication = True if an error interrupts the macro, so printer communication is not left disabled.
Set a breakpoint after Application.PrintCommunication = True, run with F5, and inspect the relevant PageSetup values. Compare them with an F8 run and check whether the active printer or other workbook state differs.
If values or output still differ, check the active printer in Excel's File > Print screen and test with an available printer or updated driver. If the driver needs extra time, test a brief delay after the commit, but do not assume a fixed delay guarantees synchronization.

Work with spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Office formats, making it easy to move everyday spreadsheet work. It does not fix Excel's PrintCommunication behavior; verify macro support separately before migrating VBA-dependent workbooks.

Frequently Asked Questions
What does Application.PrintCommunication = False do?
It tells Excel to cache PageSetup commands rather than communicate each one to the printer. Set Application.PrintCommunication = True after the changes to commit the cached commands.
Why can F8 produce a different result from F5?
F8 runs code one line at a time and introduces delays, while F5 runs normally. Those delays can expose timing differences involving printer-dependent settings or other application state.
Where should I read updated footer settings?
Read the worksheet's PageSetup footer property after setting Application.PrintCommunication back to True. If the value or printed output is still inconsistent, inspect the active printer and test its driver.
Will adding a delay always fix the macro?
No. A delay after re-enabling PrintCommunication can help test a timing issue, but it does not guarantee printer synchronization. First commit the PageSetup changes and check the active printer and driver.




