Forum Discussion
schea061
Apr 22, 2023Copper Contributor
Printing on a network printer
I am trying to create a code for printing on clicking a button on excel to print on the following network printer but i am not managing - \\P305762\IDUDOTLP2824 I seem to only be able to set .cur...
NikolinoDE
Apr 22, 2023Gold Contributor
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!