香港新浪網 MySinaBlog
« 上一篇 | 下一篇 »
Emily | 7th Jan 2006, 12:37 PM | Office Application, API / Add-in | (1541 Reads)

Printer Status

請參看 TechTrax Controlling the Printer from Word VBA , Excel 同樣地可以

例子 下載

另外參看以下 Ivan 的 Excel 例子,在 Windows 2000 Service Pack 4 測試也通過
'

'// 23rd April 2003
'// http:/www.xcelfiles.com
'// Page WMI
'// Monitor Printer Status
'// Description:
'// Displays current status for all printers on a computer.
'// (>= Win XP )


Sub GetPrinterStatus()
Dim strComputer As String
Dim Msg As String
Dim objWMIService As Object
Dim colInstalledPrinters As Object
Dim objPrinter As Object
Dim strPrinterStatus As String
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter In colInstalledPrinters
     Msg = "Name: " & objPrinter.Name & vbCrLf
     Msg = Msg & "Location: " & objPrinter.Location & vbCrLf

     Select Case objPrinter.PrinterStatus
          Case 1
               strPrinterStatus = "Other"
          Case 2
               strPrinterStatus = "Unknown"
          Case 3
               strPrinterStatus = "Idle"
          Case 4
               strPrinterStatus = "Printing"
          Case 5
               strPrinterStatus = "Warmup"
     End Select
     Msg = Msg & "Printer Status: " & strPrinterStatus & vbCrLf
     Msg = Msg & "Server Name: " & objPrinter.ServerName & vbCr
     Msg = Msg & "Share Name: " & objPrinter.ShareName & vbCr
     MsgBox Msg
Next
End Sub

Last update: 18 Jan 2006