printer port assignment in macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to access a network printer via a macro and am successful as long as I
know the current address of the printer for the specific network user. The
command Application.ActivePrinter = "printername on Ne0x:" works just fine -
except the printername is different on each computer and the Ne0x: (port?)
changes from computer to computer, and in fact changes from time to time on a
single computer. How can I code this so it will work from multiple computers
all the time?
 
Use something like:

for i = 1 to 9
err.clear
On error resume Next
Application.ActivePrinter = "printername on Ne0" & i & ":"
if err.Number = 0 then exit for
On error goto 0
Next
On Error goto 0
 
thank you very much!

what is the purpose and need of the two On Error Goto 0 commands though?
 
You may never find a legitimate port. I always like to make sure On Error
Resume Next only refers to a specific area of code - otherwise it can mask
true errors and makes debugging very difficult.
 
Back
Top