You are here VBA and Macro Program VBA to Collect list printer in your computer

Program VBA to Collect list printer in your computer

If you want to collect list printer in your computer in VBA can copy code to module to run.
Step 1: Open Excel, press ALT+F11 goto VBA editor
Step 2: In VBA, goto menu Insert->Module (if you want to create new module)
Step 3: Copy code below:
'---BEGIN COPY
'Author: Nguyen Duy Tuan - http://atoolspro.com
Sub CollectPrinters()
    Dim sComputer As String, I&
    Dim objWMIService As Object, objListPrinters As Object, objPrinter As Object
 
    sComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
                                  & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
 
    Set objListPrinters = objWMIService.ExecQuery _
                               ("Select * from Win32_Printer")
    I = 1
    For Each objPrinter In objListPrinters
        I = I + 1
        Cells(I, 1).Value = objPrinter.Name
    Next
End Sub
'---END COPY
 
Step 4: run macro "CollectPrinters" list printer's name in column A on sheet.