ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   printer port assignment in macro (https://www.excelbanter.com/excel-programming/370115-printer-port-assignment-macro.html)

DaveAlbany

printer port assignment in macro
 
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?

Tom Ogilvy

printer port assignment in macro
 
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

--
Regards,
Tom Ogilvy

"DaveAlbany" wrote:

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?


DaveAlbany

printer port assignment in macro
 
thank you very much!

what is the purpose and need of the two On Error Goto 0 commands though?

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

"DaveAlbany" wrote:

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?


Tom Ogilvy

printer port assignment in macro
 
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.

--
Regards,
Tom Ogilvy


"DaveAlbany" wrote:

thank you very much!

what is the purpose and need of the two On Error Goto 0 commands though?

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

"DaveAlbany" wrote:

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?



All times are GMT +1. The time now is 06:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com