Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Option Explicit Sub OutputGroupMembership() Dim varGroups, varItem Dim wksOut As Worksheet Dim rngOut As Range Dim varMembers Dim lngIndex As Long Dim strMemberlist As String ' this is the worksheet where the list will go ' adjust as required Set wksOut = ActiveSheet With wksOut ' add titles .Range("A1").Value = "Group name" .Range("B1").Value = "Member ID" ' first output cell Set rngOut = .Range("A2") End With ' this is the list of groups you want to get the members for varGroups = Array("Group 1", "Group 2") For Each varItem In varGroups ' output group name With rngOut .Value = varItem .Font.Bold = True End With ' move down a row Set rngOut = rngOut.Offset(1) ' get member list ' returned as a comma separated list strMemberlist = GetGroupUsers(varItem) ' split list into an array varMembers = Split(strMemberlist, ",") ' loop and output member IDs For lngIndex = LBound(varMembers) To UBound(varMembers) rngOut.Offset(, 1).Value = varMembers(lngIndex) Set rngOut = rngOut.Offset(1) Next lngIndex Next varItem End Sub Function GetGroupUsers(ByVal strGroupName As String) As String Dim objGroup, objDomain, objMember Dim strMemberlist As String, strDomain As String On Error Resume Next Set objDomain = GetObject("LDAP://rootDse") strDomain = objDomain.Get("dnsHostName") Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroupName & ",group") For Each objMember In objGroup.Members strMemberlist = strMemberlist & "," & objMember.Name Next objMember ' strip off the leading comma GetGroupUsers = Mid$(strMemberlist, 2) End Function
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.