Get members from AD group in VBA

Get the names of all the members in an active directory group – in VBA

Returns the list of names semicolon deliberated

Function getNamesADGroup(groupname As String) As String
    On Error Resume Next
    Dim ret As String
    Set Group = GetObject("WinNT://" & "corp" & "/" & groupname & ",group")

    For Each Member In Group.Members
        If Len(Member.FullName) Then _
            ret = ret & Member.FullName & ";"
    On Error GoTo 0
    If Len(ret) Then _
        getNamesADGroup = Left(ret, Len(ret) - 1)
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.