VBA & Macro Problems

Fix Excel VBA Page Setup Differences When Running with F5 and F8

Algirdas JasaitisAlgirdas Jasaitis Nov 14, 2026 869 views

Question details

The user needs to understand why an Excel VBA procedure produces different results when run with F5 versus stepped through with F8.

Fix Excel VBA Page Setup Differences When Running with F5 and 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.
Before you start

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.

Solution 1Recommended

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.

1
Group the page setup changes

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.

2
Commit the changes

After the last PageSetup assignment, add Application.PrintCommunication = True before reading the updated properties or calling PrintOut or PrintPreview.

3
Add error cleanup

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.

4
Compare execution paths

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.

5
Check the printer if needed

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.

Commit page setup changes before using their values
Other causes are possible: F8 changes execution timing, so different results can also point to other timing dependencies or changes in application state. Inspect the values and printer settings rather than assuming PrintCommunication is the only cause.
Free Microsoft Office alternative

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.

Adjust spreadsheet page setup and print settings through a familiar interfaceOpen and edit Microsoft Excel XLSX filesUse a free, lightweight suite for everyday office work
microsoft office alternative - wps office

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.