RemoveMembers 方法

       

将成员从通讯组列表中删除。

expression.RemoveMembers(Recipients)

expression  必选。该表达式返回 DistListItem 对象。

Recipients  必选,Recipients 对象。要从通讯组列表中删除的成员。

示例

本 Microsoft Visual Basic/Visual Basic for Applications 示例在默认的“联系人”文件夹中查找每个通讯组列表项目,然后确定当前用户是否是列表的成员。如果是列表的成员,那么将当前用户从通讯组列表中删除。

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myDistList As Outlook.DistListItem
Dim tmpRecips As Outlook.Recipients
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set tmpRecips = myOlApp.CreateItem(olMailItem).Recipients
tmpRecips.Add myNameSpace.CurrentUser.Name
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
                myDistList.RemoveMembers tmpRecips
                myDistList.Save
                Exit For
            End If
        Next y
    End If
Next x

如果使用 VBScript,则不创建 Application 对象,而且也不能使用命名常量。本示例说明如何使用 VBScript 执行相同任务。

Set myNameSpace = Application.GetNamespace("MAPI")
Set tmpRecips = Application.CreateItem(olMailItem).Recipients
tmpRecips.Add myNameSpace.CurrentUser.Name
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
                myDistList.RemoveMembers tmpRecips
                myDistList.Save
                Exit For
            End If
        Next 
    End If
Next