显示用于从“联系人”文件夹中选择条目的对话框

本主题介绍如何使用 SelectNamesDialog 对象在类似于 Outlook 用户界面中的“ 选择姓名 ”对话框的对话框中显示“联系人”文件夹中的条目。

  1. 查找与“联系人”文件夹对应的地址列表。 SelectNamesDialog 对象基于 AddressList 在对话框中显示整个。 若要显示“联系人”文件夹中的条目,请查找与“联系人”文件夹对应的 AddressList 。 循环访问为当前会话定义的所有地址列表,对于每个地址列表,请使用 AddressList.GetContactsFolder 将相应的文件夹与“联系人”文件夹匹配。

  2. 使用“联系人”文件夹的地址列表初始化对话框。

  3. 使用 SelectNamesDialog.Display 显示对话框。 如果 SelectNamesDialog.Display 返回 True,则所选条目将在 SelectNamesDialog.Recipients 中可用。

Sub ShowContactsInDialog() 
 Dim oDialog As SelectNamesDialog 
 Dim oAL As AddressList 
 Dim oContacts As Folder 
 
 Set oDialog = Application.Session.GetSelectNamesDialog 
 Set oContacts = _ 
 Application.Session.GetDefaultFolder(olFolderContacts) 
 
 'Look for the address list that corresponds with the Contacts folder 
 For Each oAL In Application.Session.AddressLists 
 If oAL.GetContactsFolder = oContacts Then 
 Exit For 
 End If 
 Next 
 With oDialog 
 'Initialize the dialog box with the address list representing the Contacts folder 
 .InitialAddressList = oAL 
 .ShowOnlyInitialAddressList = True 
 If .Display Then 
 'Recipients Resolved 
 'Access Recipients using oDialog.Recipients 
 End If 
 End With 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。