Here's a sample sub for copying the users in a specified group to a worksheet (output from A2):
Sub GetGroupList(strGroup As String)
On Error Resume Next
Dim objConnection, objCommand, objRecordset, objRoot, strDomain
Const ADS_SCOPE_SUBTREE = 2
Set objRoot = GetObject("LDAP://rootDSE")
'Work in the default domain
strDomain = objRoot.Get("defaultNamingContext")
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 SAMAccountName FROM 'LDAP://" & strDomain & _
"' WHERE objectClass='user' And groupName = '" & strGroup & "' ORDER BY SAMAccountName"
Set objRecordset = objCommand.Execute
objRecordset.MoveFirst
If Not objRecordset.EOF Then ActiveSheet.Cells(2, 1).CopyFromRecordset objRecordset
objRecordset.Close
objConnection.Close
End Sub
Bookmarks