I have a question for Printer object and Printers object in Excel VBA. Is any Reference library required to install in the Tool->Reference before we can use Pinter and Printers object?
I run below code, and get error "object is required" for line For Each prt In Printers. The Printers object is empty and prt-object is Nothing.
Sub ListPrinters()
Dim prt As Printer
For Each prt In Printers
Debug.Print Prt.deviceName
Next prt
End Sub
I tried to add reference library in Tool-> reference menu, and could not find any reference for Printer or Printers.
Application.Printersdoes not exist in Excel or Word, it exists only in Access (didn't check for Powerpoint or any other MS Applications).Alternative is to use the method
EnumPrinterConnectionsof the Windows Scripting Host:The loop might look a little bit strange with the
Step 2. Reason is that every printer has 2 entries in the list, the first gets the port, the second the printer name.