How to Display the Members of Contact Group in List via Outlook VBA

In general, to check a contact group’s members, you have to first open it. If you wish to see the contact group members directly in the list without opening it, you could utilize the approach shared in this article.

From my previous article – “How to Auto Display the Member Counts in Outlook Contact Groups”, you can learn how to display the count of group members in list. Similar to that, many users hope to directly show the concrete group members in a separate column. Therefore, here we will teach you how to achieve it.

Display the Members of Contact Group in List via Outlook VBA

Display Members of Contact Group in List

  1. To begin with, launch your Outlook application.
  2. Then, you can press “Alt + F11” keys to access VBA editor.
  3. In the subsequent “Microsoft Visual Basic for Applications” window, open the “ThisOutlookSession” project.
  4. Next, copy and paste the following VBA code into this project.
Private WithEvents olItems As Outlook.Items
Private objContactGroup As Outlook.DistListItem
Private objProperty As Outlook.UserProperty
Private strProperName As String
Private i As Long
Private objGroupMember As Outlook.recipient
Private strMemberName, strMembers As String

Private Sub Application_Startup()
    Set olItems = Application.Session.GetDefaultFolder(olFolderContacts).Items
    'Auto Update the members in group list on startup
    Call DisplayMembers
End Sub

'Auto Display the members of new Contact Group
Private Sub olItems_ItemAdd(ByVal Item As Object)
    If TypeOf objItem Is DistListItem Then
 
       strProperName = "Members"
       Set objProperty = objCurrentItem.UserProperties.Find(strProperName, True)
 
       Set objContactGroup = objItem
       Set objProperty = objContactGroup.UserProperties.Add(strProperName, olText, True)
 
       For i = 1 To objContactGroup.MemberCount
           Set objGroupMember = objContactGroup.GetMember(i)
           strMemberName = Split(objGroupMember.Address, "@")(0)
           strMemberName = UCase(Left(strMemberName, 1)) & Right(strMemberName, Len(strMemberName) - 1)
           strMembers = strMembers & strMemberName & "; "
       Next i

       objProperty.value = strMembers
       objContactGroup.Save
    End If
End Sub

Sub DisplayMembers()
    For Each objItem In olItems
        If TypeOf objItem Is DistListItem Then
           strProperName = "Members"
           Set objProperty = objItem.UserProperties.Find(strProperName, True)
 
           Set objContactGroup = objItem
           Set objProperty = objContactGroup.UserProperties.Add(strProperName, olText, True)
 
           'Get the names of all group members
           For i = 1 To objContactGroup.MemberCount
               Set objGroupMember = objContactGroup.GetMember(i)
               strMemberName = Split(objGroupMember.Address, "@")(0)
               strMemberName = UCase(Left(strMemberName, 1)) & Right(strMemberName, Len(strMemberName) - 1)
               strMembers = strMembers & strMemberName & "; "
           Next i
 
           objProperty.value = strMembers
           objContactGroup.Save
        End If
        strMembers = ""
    Next
End Sub

VBA Code - Display the Members of Contact Group in List

  1. Next, you should click into the “Application_Startup” subroutine and click the “Run” icon in the toolbar, which will trigger this macro at once.
  2. After that, exit the VBA editor and continue to add “Members” field to contact group list.
  • In the Contacts pane, access the correct folder.
  • Then switch to “View” tab and click “Change View” and select “List”.
  • Next hit “View Settings” button.
  • Later, click “Columns” in the newly popup dialog box.
  • In subsequent “Show Columns” dialog box, add the “Members” field by following the steps shown in the screenshot below:Add the “Members” field
  1. Finally, you could back to the contacts folder. You will see the members in the contact group list, like the following image:Group Members in List
  2. From now on, every time when you start Outlook, it’ll auto update the list of members of each contact group.
  3. Also, Outlook will auto get and display the members of new contact group in the “Members” column.

Keep Well-Prepared for Outlook Corruption

Even though Outlook is feature rich, it still cannot keep far away from damage. So you have to keep vigilant against all the potential risks. Without any doubts, you need to make a consistent and up-to-date backup for your PST data. What’s more, you’re better off keeping a remarkable and dependable PST fix tool handy, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf fix and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.