Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

May 25, 2000 09:10 AM

Showing Contacts' Email Addresses

Windows IT Pro
InstantDoc ID #8845
Rating: (2)
Downloads
8845.zip

In the June 2000 Outlook VBA on Demand column, I showed you how to use VBA in Outlook 2000 to display, for a message in your Inbox folder, the sender's email address. In this installment, I show you how to build a small application that loops through any folder containing contacts and updates the items so that an open contact's (or folder view's) email fields display the Internet email address—not the name of the contact.

Outlook uses two separate properties—one for the address and one for a display name—for each of a contact's three email fields. In the contact item and the contacts folder view, you always see the display name. Depending on how you create the contact, the display name might default to the contact's FullName property. You might think that you can simply update the Email1DisplayName property with the value in the Email1Address property, but you can't. The Email1DisplayName property is read-only. The only way you can update it is to completely recreate the email address entry—and that is what this column's application does.

Create a new module in Outlook VBA (or use an existing module in which you've been creating macros), and add a new subroutine that uses the code you see in Listing 1. The subroutine uses the PickFolder method on the Namespace object to let the user select the folder to update; then, the subroutine returns the folder's collection of items as the colContacts object variable and returns the first item in the folder. Because Outlook 2000 contacts folders can contain distribution lists (DLs) as well as contacts, the Dim objItem As Object statement declares the object that represents an item in the folder as a generic Object, not as a ContactItem object. When working in a contacts folder, you should always declare the object variable that represents an individual item as a generic Object, then use the object variable's Class property to check the actual type as you loop through the items in the folder:

If objItem.Class = olContact Then

You could also use the TypeName() function, if you prefer. After you've ensured that the item is a ContactItem, you can access its properties and make your changes. To minimize the amount of work the procedure must perform, the subroutine checks to see whether the item's first address is an Internet (i.e., SMTP) address and whether the item's display name and address are different:

If .Email1AddressType = "SMTP"
 And _
  .Email1DisplayName <> 
  .Email1Address Then

If the address is an Internet address and the two properties are different, the subroutine copies the address to a string variable, sets the Email1Address property to an empty string, then sets it again—this time to the original address:

strAddress = .Email1Address
.Email1Address = ""
.Email1Address = strAddress

The subroutine repeats this procedure for the Email2Address and Email3Address properties. If any of the properties required changes, the Saved property returns True, and the code saves the item.

Notice the structure that begins with the With objItem statement and finishes with the End With statement. Inside this structure, you can refer to any property or method of the item by simply prefixing the property or method with a period (e.g., .Email1Address instead of objItem.Email1Address). This tip will make your code easier to follow.

You can run the ConvertEmailDisplayToAddress procedure any time users complain that they can't see email addresses in a contacts folder. The procedure works with any contacts folder that you can see in your folder list.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    8 years ago
    Dec 02, 2004

    Worked like a charm.

  • Anonymous User
    8 years ago
    Nov 26, 2004

    When I use the PR_EMAIL (&H39FE001E) field, all I get is "?????????????????"

  • SUE
    8 years ago
    Aug 19, 2004

    John & Shawn, to get the SMTP address from an Exchange sender or recipient, use CDO or Redemption and the PR_EMAIL (&H39FE001E) MAPI property to obtain the SMTP address from the AddressEntry object. See http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption and http://www.cdolive.com/cdo5.htm#EMailAddressOfSender for examples.

  • Shawn
    8 years ago
    Jun 30, 2004

    This code doesn't work for users in the same Microsoft Exchange Server 5.5/2000 organization, this technique shows the internal X.400 address instead of an easy-to-read SMTP address.

  • John Alferes
    9 years ago
    Dec 05, 2003

    People in our company address book do not change. I use Outlook 2000 on a NT exchange server and get "/O=SPAN2000/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=JOHNA" for an address. I just want the company name part of the address. Thanks for any ideas.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.