How to Print Multiple Excel Worksheets as One VBA Print Job
Question details
Automate printing multiple dynamically populated worksheets within a VBA loop without manually triggering a print command for each page.

- Product
- Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Generating reports where a worksheet is populated with different worker data in a loop and needs to be printed directly.
- Observed behavior
- Using PrintPreview pauses the macro, requiring the user to manually interact with the preview window for every iteration instead of running as a single automated print job.
Ensure your default printer is online, connected, and has enough paper, as automating the print job will bypass preview screens and send all generated pages directly to the print queue.
Use PrintOut with DoEvents in Your VBA Loop
Replace the PrintPreview method with PrintOut to send pages directly to the printer, and utilize DoEvents to ensure the print spooler keeps up with the macro execution.
The PrintPreview method pauses code execution until the user manually closes the preview window. To print multiple iterations automatically and continuously, you must use the PrintOut method instead.
Adding DoEvents immediately after the PrintOut command is crucial. It yields execution to the operating system temporarily, allowing the system's print spooler to process the job properly, preventing Excel from crashing or skipping pages during rapid loops.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor and locate the module containing your printing loop.
Find the line of code that reads `ws.PrintPreview` (or similar) inside your loop. Change it to `ws.PrintOut Copies:=1`.
Insert a new line immediately below the PrintOut command and type `DoEvents`.
Save your code and run the macro. The loop will now process each worker's data and send all sheets directly to the printer as a continuous job without pausing.

Automate Printing with Macros in WPS Spreadsheet
WPS Spreadsheet offers excellent compatibility with Excel VBA, allowing you to run loops, use the PrintOut method, and automate your daily printing tasks seamlessly.
- 1. Open Your Macro Workbook: Launch WPS Spreadsheet and open your existing .xlsm or .xls file containing the print loop macro.
- 2. Access the VBA Editor: Navigate to the Developer tab on the ribbon and click on 'VBA Editor', or simply press Alt + F11.
- 3. Modify and Run: Update your loop to use the `PrintOut` method combined with `DoEvents`, then execute the macro to seamlessly print all dynamically generated worksheets.

Frequently Asked Questions
Why does my VBA loop pause at every page when trying to print?
If your code uses the `PrintPreview` method, VBA execution intentionally pauses until the preview window is manually closed by the user. Change `PrintPreview` to `PrintOut` to print automatically without pausing.
Can I combine all iterations of a loop into a single PrintPreview window?
No, the `PrintPreview` method is strictly designed to preview a single print operation at a time. It cannot automatically gather and combine sheets generated sequentially within a VBA loop into one master preview.
What is the purpose of adding DoEvents after PrintOut?
`DoEvents` passes control from the macro to the operating system temporarily. This allows the Windows print spooler to properly process the incoming print jobs, preventing your fast-running VBA macro from outrunning the printer and causing errors or skipped pages.
How can I print multiple existing worksheets as one single print job?
If you want to print existing worksheet tabs rather than generating them dynamically in a loop, you can group them. In VBA, use `Sheets(Array("Sheet1", "Sheet2")).PrintOut` to send multiple specific sheets as a single combined print job.




