Private Sub CommandButton1_Click() On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject('ADODB.Connection') Set objCommand = CreateObject('ADODB.Command') objConnection.Provider = 'ADsDSOObject' objConnection.Open 'Active Directory Provider' Set objCommand.ActiveConnection = objConnection objCommand.Properties('Page Size') = 1000 objCommand.Properties('Searchscope') = ADS_SCOPE_SUBTREE objCommand.CommandText = _ 'SELECT Name FROM 'LDAP://dc=XXX,dc=com' WHERE objectCategory='user'' 'search all users from the domn XXX Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Dim currCell As Range Set currCell = Range('A1') Do Until objRecordSet.EOF currCell.Value = objRecordSet.fields('Name').Value Set currCell = currCell.Offset(1, 0) objRecordSet.MoveNext Loop End Sub
https://blog.csdn.net/weixin_29129919/article/details/119410825
标签:objRecordSet,vba,Set,ad,currCell,获取,objCommand,objConnection From: https://www.cnblogs.com/Insist-Y/p/16933592.html