Printer Problem

D

Dean P.

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.
 
J

Joel

You could ping the printer by its IP address to determine if it is online

Sub Ping()
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '16.37.100.16'")
For Each objStatus In objPing
If objStatus.StatusCode = 0 Then
MsgBox ("On-Line")
Else
MsgBox ("Off-Line")
End If
Next
End Sub
 
U

urkec

Dean P. said:
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.
 

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