Excel VBA Macro to Print to a Specific Printer and Paper Size
Question details
The user needs an Excel VBA macro that can assign a specific printer, customize paper sizes (such as statement or letter), and export selected ranges to PDF without reusing previous print settings.
- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating automated buttons in a cashout workbook to quickly print specific selected ranges to designated printers and export as PDF with exact paper dimensions.
- Observed behavior
- The current macros default to the last used printer settings instead of applying the intended custom printer and paper size rules.
Ensure your target printer is properly installed, turned on, and connected to your computer. Note that printer naming conventions and custom paper size parameters (like statement size) can vary widely depending on your specific Windows printer driver.
Configure Page Setup and Active Printer via VBA
Define the print area, page orientation, paper size, and destination printer directly in your VBA code before executing the print command.
To prevent Excel from reusing the last active printer settings, you must explicitly declare the Application.ActivePrinter property and configure the PageSetup properties for your worksheet before calling PrintOut.
Press Alt + F11 in Excel to open the Visual Basic for Applications editor, then insert a new Module from the Insert menu.
Use the Worksheets("Sheet1").PageSetup object to set .PrintArea = "A1:D20", .Orientation = xlPortrait, and .PaperSize = xlPaperStatement.
Assign the specific printer network path or name using a command like Application.ActivePrinter = "Your Printer Name on Ne01:".
Call the Range("A1:D20").PrintOut method to send the configured job directly to the designated printer.
Export a Selected Range as a Letter-size PDF
Use the ExportAsFixedFormat method to save a specific selection directly to a PDF file with letter-size dimensions.
Consult Stack Overflow for Complex Printer Driver Issues
Because statement-size paper settings can be highly specific to unique Windows drivers, you may need community help for advanced configurations.
Easily Run VBA Macros and Print with WPS Spreadsheet
WPS Spreadsheet offers robust support for VBA macros, allowing you to automate complex printing tasks, define specific paper sizes, and export to PDF seamlessly without altering your existing scripts.
- 1. Enable Macros: Open WPS Spreadsheet, go to the Developer tab, and enable macros to access the VBA environment.
- 2. Edit your Script: Click on 'Visual Basic' to paste or modify your existing print and PDF export macros.
- 3. Run the Automation: Assign your macros to worksheet buttons and click them to automatically print to your specific printer.

Frequently Asked Questions
Why does my VBA macro print to the wrong printer?
If Application.ActivePrinter is not explicitly defined in your macro code before the PrintOut method is called, the program will default to the last used printer. You must specify the exact printer name and port in your script.
How do I find the correct printer port for my VBA code?
You can easily find the correct string by recording a new macro. Start recording, open the Print dialog, select your desired printer, and stop recording. Open the VBA editor to view the exact printer string (e.g., 'PrinterName on Ne02:') generated by Excel.
What is the VBA constant for statement-size paper?
The standard VBA constant is xlPaperStatement. However, if your specific printer driver does not natively support this mapping, you might need to assign a custom paper size ID integer that is unique to your driver's configuration.
Can I export to PDF without changing my default printer?
Yes. Using the ExportAsFixedFormat method in VBA saves the range or worksheet as a PDF directly. This operation operates independently of the ActivePrinter property, leaving your print spooler defaults untouched.




