Forum Discussion
Printing on a network printer
To print to a network printer from Excel VBA, you can use the Printer object to set the printer and then use the PrintOut method.
Here's an example code that you can modify to print to your network printer:
Sub PrintToNetworkPrinter()
Dim myPrinter As String
' Set the name of the network printer
myPrinter = "\\P305762\IDUDOTLP2824"
' Set the printer to the network printer
Application.ActivePrinter = myPrinter
' Print the active sheet
ActiveSheet.PrintOut
End Sub
In this example, the name of the network printer is stored in the "myPrinter" variable.
You can modify this variable to match the name of your network printer.
The code then sets the active printer to the network printer using the ActivePrinter property. This will direct all subsequent print operations to the network printer until the printer is changed again.
Finally, the code prints the active sheet using the PrintOut method. You can modify this method to print a specific range or to print multiple sheets if needed.
Hope it helped!
- HansVogelaarApr 22, 2023MVP
Try the following:
- Select \\P305762\IDUDOTLP2824 as printer in the Printer dialog (you don't have to actually print anything).
- Activate the Visual Basic Editor.
- Activate the Immediate window (Ctrl+G).
- Type ? Application.ActivePrinter and press Enter.
- You'll probably see something like \\P305762\IDUDOTLP2824 on Ne01: (the last part may vary).
- Copy the entire result, and paste that into your code.