View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default How to check a printer's availability

I think that this would be useful to me, but every time I run it, I get a
status return of 3, even when the printer is turned off.

Is there something I need in addition to this script?

Thanks for the help.

"urkec" wrote:

"clara" wrote:

Hi all,

Two bad things happened during my worksheet printing:

the first time the notepad is not connected to network before I click the
print button, but after I connect the notepad, the worksheet could not be
printed out correctly.
the second time the printer is out of paper before I click the print button,
same thing happened as the first time.

So I would like to know how to check the availability of a printer before
printing?

Thank you very much.

Clara



I'm not sure this is exactly what you need, but you can get some information
about printer status using WMI. You need administrator privileges to run it:


Sub WMITest()

'get active printer
strPrinterName = Application.ActivePrinter

'connect to WMI on local computer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

'enumerate printers
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

'Printer status:
'1 Other
'2 Unknown
'3 Idle
'4 Printing
'5 Warmup
'6 Stopped printing
'7 Offline

'get active printer status
For Each objPrinter In colInstalledPrinters

If InStr(strPrinterName, objPrinter.Name) Then
Debug.Print objPrinter.Name
If objPrinter.PrinterStatus = 1 _
Or objPrinter.PrinterStatus = 2 Then
Debug.Print "Printer not responding"
Else
Debug.Print "Printer status OK"
End If
End If

Next


End Sub


Hope this helps.

--
urkec