Thread: Printer Problem
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
urkec urkec is offline
external usenet poster
 
Posts: 131
Default Printer Problem

"Dean P." wrote:


I am using the Call CopyPrintData(ActiveSheet) to print. There are times
when the printer is offline or defined at remote locations when the call to
CopyPrintData(ActiveSheet) task creates a continues hourglass and will not
complete.

Is there away to build logic if the call CopyPrintData(ActiveSheet) task
takes more than 45 seconds to end the task?

Please help me with logic to resolve this issue.

Thank you vey much.


Sub PrinterTest()

'get active printer
strPrinterName = Application.ActivePrinter

'connect to WMI on local computer
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& "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
Debug.Print "Network printer: " & _
(objPrinter.Local And objPrinter.Network)
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