Display a Dialog Box for Selecting Entries from the Contacts Folder

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

This topic describes how to use the SelectNamesDialog object to display entries from the Contacts folder in a dialog box that resembles the Select Names dialog box in the Outlook user interface.

  1. Look for the address list that corresponds with the Contacts folder.The SelectNamesDialog object displays entires in a dialog box based on an AddressList. To display entries in the Contacts folder, look for the AddressList that corresponds with the Contacts folder. Iterate through all the address lists defined for the current session, and for each address list, use AddressList.GetContactsFolderto match the corresponding folder with the Contacts folder.

  2. Initialize the dialog box with the address list of the Contacts folder.

  3. Use SelectNamesDialog.Display to display the dialog box. If SelectNamesDialog.Display returns True, then selected entries will be available in SelectNamesDialog.Recipients.

Sub ShowContactsInDialog() 
 Dim oDialog As SelectNamesDialog 
 Dim oAL As AddressList 
 Dim oContacts As Folder 
 Set oDialog = Application.Session.GetSelectNamesDialog 
 Set oContacts = _ 
 '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 
 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