ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   active Printer (https://www.excelbanter.com/excel-programming/391530-active-printer.html)

Libby

active Printer
 
Hi

Does anyone know how to return the number of pending jobs in the active
printer?

Many thanks in advance.
Libby


urkec

active Printer
 

"Libby" wrote:

Hi

Does anyone know how to return the number of pending jobs in the active
printer?

Many thanks in advance.
Libby


I used this to get print job count and some other data (Windows XP / Office
2007):

Sub getPrintJobs()

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

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

'get the active printer name
For Each objPrinter In colInstalledPrinters
If InStr(ActivePrinter, objPrinter.Name) Then
strPrinterName = objPrinter.Name
End If
Next

If strPrinterName = "" Then
MsgBox "Error getting the printer name"
Exit Sub
End If

'get pending jobs for the active printer
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob " & _
"where DriverName = '" & strPrinterName & "'")

'job count
Debug.Print "Pending jobs " _
& "for " & strPrinterName _
& ": " & colPrintJobs.Count

'print job data
For Each objPrintJob In colPrintJobs
Debug.Print "Job name" & ": " _
& objPrintJob.Document _
& " , Total pages" & ": " & _
objPrintJob.TotalPages _
& " , Job status" & ": " _
& objPrintJob.Status
Next

End Sub

Hope you can use it.

--
urkec

NickHK[_3_]

active Printer
 
This will tell you pretty much everything about your printer(s)/queue:
http://vb.mvps.org/samples/project.asp?id=PrnInfo

NickHK

"Libby" ...
Hi

Does anyone know how to return the number of pending jobs in the active
printer?

Many thanks in advance.
Libby




Libby

active Printer
 
Thanks, that worked well in Excel 2003, though Excel 2000 didn't seem to like
it

"urkec" wrote:


"Libby" wrote:

Hi

Does anyone know how to return the number of pending jobs in the active
printer?

Many thanks in advance.
Libby


I used this to get print job count and some other data (Windows XP / Office
2007):

Sub getPrintJobs()

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

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

'get the active printer name
For Each objPrinter In colInstalledPrinters
If InStr(ActivePrinter, objPrinter.Name) Then
strPrinterName = objPrinter.Name
End If
Next

If strPrinterName = "" Then
MsgBox "Error getting the printer name"
Exit Sub
End If

'get pending jobs for the active printer
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob " & _
"where DriverName = '" & strPrinterName & "'")

'job count
Debug.Print "Pending jobs " _
& "for " & strPrinterName _
& ": " & colPrintJobs.Count

'print job data
For Each objPrintJob In colPrintJobs
Debug.Print "Job name" & ": " _
& objPrintJob.Document _
& " , Total pages" & ": " & _
objPrintJob.TotalPages _
& " , Job status" & ": " _
& objPrintJob.Status
Next

End Sub

Hope you can use it.

--
urkec



All times are GMT +1. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com