Tạo một truy vấn Ldap trong Excel
Chào buổi sáng tất cả,
Tôi muốn biết liệu có thể sử dụng Microsoft Excel để thực hiện truy vấn Ldap hay không và nếu có thể, tôi có thể thực hiện điều đó như thế nào hoặc nếu ai đó có bất kỳ khó khăn nào hãy đưa tôi vào cách phù hợp để thực hiện điều này.
Cảm ơn tất cả.
Câu trả lời:
Một cái gì đó như thế này?
Tùy chọn Rõ ràng Riêng tư Const sDomain As String = "MyDomain" 'Miền của bạn ở đây' Có tham chiếu đến Đối tượng Dữ liệu ActiveX của Microsoft 2.8 Thư viện Public Sub ShowADPrinters () Dim oConn As ADODB.Connection Dim oCmd As ADODB.Command Dim rs As ADODB.Recordset Dim ô As Range Dim i As Long Dim sPrinterList () As String Application.ScreenUpdating = False On Error GoTo ErrHandlr 'Tạo đối tượng kết nối và lệnh. Đặt oConn = ADODB.Connection Set mới oCmd = New ADODB.Command 'Mở kết nối. oConn.Provider = "ADsDSOObject" oConn.Open "Active Directory Provider" 'Tạo một đối tượng lệnh cho kết nối này. Đặt oCmd.ActiveConnection = oConn 'Soạn chuỗi tìm kiếm. oCmd.CommandText = "SELECT printName, printColor" & _ "FROM 'LDAP: // DC =" & sDomain & ", DC = local'" & _ "WHERE objectCategory = 'printQueue'" 'Thực hiện truy vấn. Đặt rs = oCmd.Execute rs.MoveFirst ReDim sPrinterList (rs.RecordCount + 1, 1) i = 0 Do While Not rs.EOF 'Debug.Print rs! PrintName sPrinterList (i, 0) = rs! PrintName sPrinterList (i, 1) = rs! PrintColor rs.MoveNext i = i + 1 Loop Set cell = Range ("A1") cell.Value = "Printer Name" cell.Offset (0, 1) .Value = "Color Printer" Đối với i = 0 Đến UBound (sPrinterList) cell.Offset (i + 1, 0) = sPrinterList (i, 0) cell.Offset (i + 1, 1) = sPrinterList (i, 1) Next ErrHandlr: Đặt oCmd = Nothing oConn.Close Đặt oConn = Nothing End SubEd Ferrero www.edferrero.com
Comments
Post a Comment