Try out this query it may help you out.
Code:
Option Explicit
Private Const tDomain As String = "MyDomain" ‘ your current domain
Public Sub ShowADPrinters()
Dim tConn As ADODB.Connection
Dim tCmd As ADODB.Command
Dim rs11 As ADODB.Recordset
Dim Cell1 As Range
Dim i As Long
Dim tPrinterList() As String
Application1.ScreenUpdating = False
On Error GoTo ErrHandler
Set tConn = New ADODB.Connection
Set tCmd = New ADODB.Command
tConn.Provider = "ADsDSOObject"
tConn.Open "Active Directory Provider"
' Create a command object for this connection.
Set tCmd.ActiveConnection = tConn
' Compose a search string.
tCmd.CommandText = "SELECT printerName, printColor " & _
"FROM 'LDAP://DC=" & tDomain & ",DC=local' " & _
"WHERE objectCategory='printQueue' "
' Execute the query.
Set rs11 = oCmd.Execute
rs11.MoveFirs11t
ReDim tPrinterList(rs11.RecordCount + 1, 1)
i = 0
Do While Not rs11.EOF
'Debug.Print rs11!printerName
tPrinterList(i, 0) = rs11!printerName
tPrinterList(i, 1) = rs11!printColor
rs11.MoveNext
i = i + 1
Loop
Set Cell1 = Range("A1")
Cell1.Value = "Printer Name"
Cell1.Offset(0, 1).Value = "Colour Printer"
For i = 0 To UBound(tPrinterList)
Cell1.Offset(i + 1, 0) = tPrinterList(i, 0)
Cell1.Offset(i + 1, 1) = tPrinterList(i, 1)
Next
ErrHandlr:
Set oCmd = Nothing
tConn.Close
Set tConn = Nothing
End Sub
Bookmarks