
Tips.Net > WordTips Home > Working with Other Programs > Working with Outlook > Accessing a List of Outlook Contacts
Summary: The information stored in Outlook can be utilized in Word, the same as with any other Microsoft Office application. Getting at that information from within Word, however, can sometimes be tricky. This tip explains a couple of ways you can get at contact information that you need to use in your documents. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
Doug recently wrote about a problem he was having creating a dialog box that would allow users to select from a list of Outlook contacts. Doug wanted users to pick a contact, and then create a business document using the single contact name.
There are a couple of ways you can approach this problem. The first is to simply add to the toolbar or the Insert menu an Address Book tool that users can utilize to select contacts. You can add this option by following these steps:
Now you should be able to choose the command, which displays the Select Name dialog box and allows you to select a contact. If your contacts are not displayed, then you may not have the Address Book option installed for Word. If this is the case, you may need to run the Office or Word Setup program again and make sure that it is installed.
Because of the convoluted way in which address books are handled in Office, you may want to do a bit more research on this topic. (For instance, address books could come from Outlook contacts, from Outlook Express address book, from an Exchange server, etc. The source used for the address book can affect exactly how you display and select contacts in Word.) For more information, do a search in the Microsoft Knowledge Base for "Contact List" or "Address Book."
If you are automating the creation of your documents, and you want your macros to display a list of contacts from which the user can choose, then you are getting into some fairly advanced areas. Assuming that the user running the macros has Outlook installed on their system, you can access the Outlook object model from within a Word macro and pull a list of the contacts from their Contact list. The following Word macro shows how this can be done:
Sub ListContacts()
Dim oOL As Object
Dim oNS As Object
Dim oContacts As Object
Dim oContactItem As Object
Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNameSpace("MAPI")
Set oContacts = oNS.Folders(1).Folders("Contacts")
For Each oContactItem In oContacts.Items
Selection.TypeText oContactItem & vbCrLf
Next
Set oContactItem = Nothing
Set oContacts = Nothing
Set oNS = Nothing
Set oOL = Nothing
End Sub
This macro adds the contact names to the current document, but it could just as easily compile those contact names and add them to a drop-down list in a custom dialog box. The user could then select a name, and that name could be used to extract additional information from the Outlook contact item (oContactItem in this macro). What sort of additional information can be extracted? As anyone who has used Outlook knows, you can store tons of information on any given contact. In fact, the VBA help file for Outlook lists over 140 different properties applicable to contact items.
Tip #1554 applies to Microsoft Word versions: 97 2000 2002 2003
Great Idea! Word is a tool to get what you really want—printed output. This means you need to make sure that Word works as well as possible with your printer, whether it is sitting on your desk or in a room down the hall.
Check out WordTips: Printing and Printers today!
Have thousands of WordTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips