GetMember Method

Microsoft Outlook Visual Basic

GetMember Method

       

Returns a Recipient object representing a member in a distribution list.

expression.GetMember(Index)

expression   Required. An expression that returns a DistListItem object.

Index   Required Long. The index number of the member to be retrieved.

Example

This Microsoft Visual Basic/Visual Basic for Applications example locates every distribution list in the default Contacts folder and determines whether the list contains the current user.

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myDistList As Outlook.DistListItem
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
For x = 1 To myFolder.Items.Count
    If TypeName(myFolder.Items.Item(x)) = "DistListItem" Then
        Set myDistList = myFolder.Items.Item(x)
        For y = 1 To myDistList.MemberCount
            If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
                MsgBox "Your are a member of " & myDistList.DLName
            End If
        Next y
    End If
Next x

If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(10)
For x = 1 To myFolder.Items.Count
    If TypeName(myFolder.Items.Item(x)) = "DistListItem" Then
        Set myDistList = myFolder.Items.Item(x)
        For y = 1 To myDistList.MemberCount
            If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
                MsgBox "Your are a member of " & myDistList.DLName
            End If
        Next 
    End If
Next