title: how do I get a list of all the members of a group using VBA?
body: <p>I found some code on the internet and tinkered with it to list all the members of a group in Active Directory.</p>
  
  <p>my final result must be similar to this:</p>
  
  <p>E.g.</p>
  
  <pre><code>Group 1, User 1
  Group 1, User 2
  Group 2, User 1
  Group 3, User 3
  </code></pre>
  
  <p>Etc</p>
  
  <pre><code>Function GetGroupUsers(ByVal strGroupName As String) As String
  
      Dim objGroup, objDomain, objMember
      Dim strMemberlist As String, strDomain As String
      Set objDomain = GetObject("LDAP://rootDse")
      strDomain = objDomain.Get("dnsHostName")
  
      Debug.Print strGroupName
      Debug.Print strDomain
  
      Set objGroup = GetObject("WinNT://" &amp; strDomain &amp; "/" &amp; strGroupName &amp; ",group")
      Debug.Print objGroup
  
      Dim i
      i = 0
  
      For Each objMember In objGroup.Members
          strMemberlist = strMemberlist &amp; "," &amp; objMember.Name
          Debug.Print strMemberlist
          i = i + 1
          Debug.Print i
      Next objMember
      ' strip off the leading comma
      GetGroupUsers = Mid$(strMemberlist, 2)
  
  End Function
  </code></pre>