Printing Problems

Print an Excel File to a Specific Printer Using Access VBA

Tauseeq MagsiTauseeq Magsi Nov 22, 2026 868 views

Question details

Print an Excel invoice from Access VBA to a designated dot-matrix printer without changing the Windows default printer.

Print an Excel File to a Specific Printer Using Access VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the printer in Excel

In Excel, open File > Print and select the dot-matrix printer. You do not need to print a page.

2
Find the exact printer value

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:.

3
Set the printer and print

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

4
Test and handle errors

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.

Use Excel's Exact ActivePrinter Value in Access VBA
Do not guess the port: The printer name and port must match Excel's returned value exactly. If error 1004 persists, select the printer again and recheck the value in the Immediate window for the user and machine running the code.
Free Microsoft Office alternative

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.

Open and print spreadsheet invoices from a familiar interfaceCompatible with Microsoft Excel XLS and XLSX formatsFree and lightweight for everyday office tasksMove existing spreadsheet files into a familiar workspace
microsoft office alternative - wps office

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.