Members Property Example

This Visual Basic for Applications example uses the Members property of an AddressEntry object to display all the members in an e-mail alias in the Global Address List named "My Group". To access the Members property, the DisplayType of the AddressEntry must be a distribution list.

To use this example, substitute the name of an e-mail alias for which you would like to view the members.

Sub DisplayMembersOfAlias()
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOlApp.GetNameSpace("MAPI")
    'Set myAddressList to
    'the Global Address List
    'within the AddressLists
    'collection.
    Set myAddressList = myNameSpace.AddressLists("Global Address List")
    'Set myAddressEntry
    'to the entry in the
    'AddressEntries
    'collection named
    '"My Group" which is
    'a distribution list.
    Set myAddressEntry = myAddressList.AddressEntries("My Group")
    'Display each member in the
    'alias.
    For Each memberEntry In myAddressEntry.Members
      MsgBox memberEntry
    Next
End Sub