I have the following code that I recorded with the Macro recorder in Excel to print a user selection to a USB printer.
Application.ActivePrinter = "HP LaserJet P2035 UPD PCL 5 on Ne01:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"HP LaserJet P2035 UPD PCL 5 on Ne01:", Collate:=True
The code works as intended, but I am wondering if there is a way I can rewrite this code so its not port dependent. The way the code is currently written, it needs to know which USB port the printer is plugged into (I believe this is controlled by the Ne01 in the code), but I plan to install this code on numerous computers and inevitably the printer will not always be plugged into the same USB port. I would like to have the code find the printer no matter what USB port it is plugged into and print to it. I hope that someone has some ideas of how to write this code in variable form to achieve this. Thank you in advance for your help.
Application.ActivePrinter = "HP LaserJet P2035 UPD PCL 5 on Ne01:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"HP LaserJet P2035 UPD PCL 5 on Ne01:", Collate:=True
The code works as intended, but I am wondering if there is a way I can rewrite this code so its not port dependent. The way the code is currently written, it needs to know which USB port the printer is plugged into (I believe this is controlled by the Ne01 in the code), but I plan to install this code on numerous computers and inevitably the printer will not always be plugged into the same USB port. I would like to have the code find the printer no matter what USB port it is plugged into and print to it. I hope that someone has some ideas of how to write this code in variable form to achieve this. Thank you in advance for your help.