NetWork Printer Selection Problems

L

leerem

I need some assistance please with a network printer selection.

I use two network printers one colour the other non-colour and I need to
print documents to both printers at different times during the day. The two
printers are in different parts of the building. I currently use code to
designate the printer required, such as:

Application.ActivePrinter = "Colour Admin Office on Ne03:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"Colour Admin Office on Ne03:", Collate:=True
Application.ActivePrinter = "Lexmark E323 on Ne02:" ' reverts back to
non-colour

The problem I have is that for some reason unknown to myself the Printer
Name changes; for example from; "Colour Admin Office on Ne03 too "Colour
Admin Office on Ne05" which caused an error when the routine is run.
Without going down the route of asking the user to identify the Printer
every time, is there a way using VB, to identify the correct printer based on
the first part of the name? It only seems to be the last character that
changes each time.

Any help would be much appreciated
Regards Lee
 
D

Dave Peterson

As long as the number is the only thing changing, I'd use something like:

Sub testme()
Dim iCtr As Long
Dim FoundIt As Boolean
Dim CurPrinter As String

CurPrinter = Application.ActivePrinter

FoundIt = False
For iCtr = 0 To 99
On Error Resume Next
Application.ActivePrinter = "Colour Admin Office on Ne" _
& Format(iCtr, "00") & ":"
If Err.Number = 0 Then
FoundIt = True
Exit For
Else
'keep looking
Err.Clear
End If
Next iCtr
On Error GoTo 0

If FoundIt = False Then
MsgBox "No printer close to that name"
Else
'do the real work
'and change it back
Application.ActivePrinter = CurPrinter
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top