FreemanRU СПАСИБО!
А как сделать так чтобы он каждую группу записывал в отдельную ячейку?
Я написал вот так, но там есть несовпадения объектов Object required (Error 424)
Sub getuserinfo()
Cells.Clear
Set objConnection = CreateObject("ADODB.Connection")
objConnection.provider = "ADsDSOObject"
objConnection.Open ("Active Directory Provider")
CommandText = "Select cn, name, memberOf"
CommandText = CommandText + " from 'LDAP://DC= DOM ,DC=com'"
CommandText = CommandText + " where objectClass='person' and objectClass<>'computer'"
CommandText = CommandText + " ORDER BY cn"
Set objRecordset = CreateObject("ADODB.Recordset")
objRecordset.Open CommandText, objConnection
n = 1
m = 3
While Not objRecordset.EOF
Cells(n, 1).Value = objRecordset.fields("cn").Value
Cells(n, 2).Value = objRecordset.fields("Name").Value
For Each strGroup In objRecordset.fields("MemberOf").Value
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Cells(n, m).Value = strGroupName.Value - ошибка ТУТ
!
m = m + 1
Next
objRecordset.MoveNext
n = n + 1
Wend
End Sub
Добавлено: Спасибо большое!
Разобрался сам
Sub getuserinfo()
Cells.Clear
Set objConnection = CreateObject("ADODB.Connection")
objConnection.provider = "ADsDSOObject"
objConnection.Open ("Active Directory Provider")
CommandText = "Select cn, name, memberOf"
CommandText = CommandText + " from 'LDAP://DC=DOM,DC=com'"
CommandText = CommandText + " where objectClass='person' and objectClass<>'computer'"
CommandText = CommandText + " ORDER BY cn"
Set objRecordset = CreateObject("ADODB.Recordset")
objRecordset.Open CommandText, objConnection
n = 2
While Not objRecordset.EOF
Cells(n, 1).Value = objRecordset.fields("cn").Value
Cells(n, 2).Value = objRecordset.fields("Name").Value
m = 3
Cells(1, 2).Value = objRecordset.fields("MemberOf").Value
If Cells(1, 2).Value = "" Then GoTo 12
For Each strGroup In objRecordset.fields("MemberOf").Value
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Cells(n, m).Value = strGroupName
m = m + 1
Next
12: objRecordset.MoveNext
n = n + 1
Wend
End Sub