Print an Excel File to a Specific Printer Using Access VBA
Question details
Print an Excel invoice from Access VBA to a designated dot-matrix printer without changing the Windows default printer.

- Product
- Microsoft Access and Microsoft Excel
- Device & OS
- Windows
- Scenario
- An Access VBA procedure opens an Excel invoice and sends a worksheet to a specific printer.
- Observed behavior
- Assigning a printer name and port to Excel's ActivePrinter property can produce run-time error 1004 if the value does not match the printer identifier Excel expects.
Make sure the dot-matrix printer is installed and available to the Windows user running Access and Excel. Open Excel and confirm that the printer appears under File > Print.
Use Excel's Exact ActivePrinter Value in Access VBA
Select the printer in Excel, copy its exact name and port, and use that value before printing the invoice.
In Excel, open File > Print and select the dot-matrix printer. You do not need to print a page.
Press Alt+F11 to open the Visual Basic Editor, then press Ctrl+G to open the Immediate window. Enter ? Application.ActivePrinter and press Enter. Copy the entire result, including the port and colon, such as Dot Matrix Printer on Ne01:.
In the Access VBA procedure, use the Excel application and worksheet objects already associated with your invoice. Replace the example string below with the exact value returned by Excel, keeping the quotation marks: Dim originalPrinter As String originalPrinter = objXLApp.ActivePrinter objXLApp.ActivePrinter = "Dot Matrix Printer on Ne01:" objDataSheet.PrintOut Copies:=1, Collate:=True objXLApp.ActivePrinter = originalPrinter
Run the Access procedure and confirm that the invoice prints on the intended printer. Add error handling that restores originalPrinter if an error occurs after the original value is saved.

Manage and Print Excel Invoices with WPS Office
WPS Office is a free, lightweight, easy-to-use alternative for opening and printing spreadsheets. Its familiar interface and Excel format support make it easier to move existing invoice files, although it does not fix Microsoft Access or Excel VBA automation errors.

Frequently Asked Questions
Why does setting Excel's ActivePrinter cause error 1004?
Excel may not recognize the supplied printer name and port. Select the printer in File > Print, then run ? Application.ActivePrinter in the Excel VBA Immediate window and copy the complete result.
Do I need quotation marks around the printer name in VBA?
Yes. When assigning a literal value, put the entire printer name and port inside quotation marks, such as "Dot Matrix Printer on Ne01:".
Will this change the Windows default printer?
The code sets the ActivePrinter property of the Excel application object rather than changing the Windows default printer. Save and restore the previous Excel ActivePrinter value after printing.
Can I reuse a printer port from another computer?
Do not assume the port is the same. On the computer and user account running the procedure, select the printer in Excel and check Application.ActivePrinter in the Immediate window.




