Verifying Printer with Excel VBA

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

Hi...
I know that I can change the printer with:
Application.Activeprinter="HPPhpoto on LPT1:"

Is there any way of checking the existance of the printer before using the
Activeprinter change?
I just want to be sure the printer exist before I create an error if it
doesn't... because I'm dealing with over 100 printers!
Craig
 
Hi Craig

Try it and see if it errs, if so, reset to previous, if not, ok. Like this:

Sub test()
If PrinterOK("HPPhpoto on LPT1:") Then
MsgBox "OK"
Else
MsgBox "Not cool"
End If
End Sub

Function PrinterOK(sPrinterName As String) As Boolean
Dim sCurrPrinter As String
sCurrPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = sPrinterName
DoEvents
If Err.Number <> 0 Then
Application.ActivePrinter = sCurrPrinter
DoEvents
PrinterOK = False
Else
PrinterOK = True
End If
End Function

HTH. Best wishes Harald
 
Thanks Harald... worked like a charm!
Craig


Harald Staff said:
Hi Craig

Try it and see if it errs, if so, reset to previous, if not, ok. Like
this:

Sub test()
If PrinterOK("HPPhpoto on LPT1:") Then
MsgBox "OK"
Else
MsgBox "Not cool"
End If
End Sub

Function PrinterOK(sPrinterName As String) As Boolean
Dim sCurrPrinter As String
sCurrPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = sPrinterName
DoEvents
If Err.Number <> 0 Then
Application.ActivePrinter = sCurrPrinter
DoEvents
PrinterOK = False
Else
PrinterOK = True
End If
End Function

HTH. Best wishes Harald
 
Back
Top