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 .currentprinter but am unsure as to how to divert printing on the above network printer
Could you please help ?
- schea061Copper Contributor
I am still not managing unfortunately.
So let me explain my problem
Attached is my excel sheet. I would like to print the "sticker ( code and barcode ) on a Zebra Printer which is remotely connected.
The reason i want to use network path or IP address is because the excel sheet will be accessed from 9 different PCs all of which have the printers saved with different names or ports.
On the other hand, if i "map" them it would "standardise" even i get new PCs in my offices.
So this is the info i have
The button " Print Labels on label Printer - IDU Office" is meant to print on Zebra printer connected on \\P305762\IDUDOTLP2824 but when i attempt to print via that network path it says invalid so i temporarily used the Zebra printer i have connected to my PC. And it is the correct path as when i use \\P305762\IDUDOTLP2824 in windows explorer it brings up the mentioned label printer .
The button "Print Labels on Xerox Printer - IDU Front Desk" is meant to print on the reception printer - and it does, only from one PC as i used the print name and port of the reception printer on that particular PC, but cannot divert to print on it from other PCs -
Kindly help hehe.
Thanks
Dr. Aaron Schembri
- Patrick2788Silver Contributor
\\P305762\IDUDOTLP2824 is the Print Server.
To obtain the name of the printer, you may enter this command at a command line:
wmic printer list brief
- NikolinoDEGold 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!
- schea061Copper Contributor
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.