2

I'm writing a VBA macro which will scan my inbox, determine who emails me a lot and then automatically add them (with a number of select fields) as a new contact into my Personal Address Book.

To start, I've written some pretty simple VBA which looks through all the emails in the inbox and displays the SenderEmailAddress for those who are on the Microsoft Exchange server:

Dim objEmail As Outlook.MailItem

Set objNS = GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

For Each objEmail In objInbox.Items
    If objEmail.SenderEmailType = "EX" Then
        Debug.Print objEmail.SenderEmailAddress
    End If
Next

I now have the email address, so the next step would be to look them up on the GAL. However the solutions I've seen involve scanning the entire GAL, which in a company where there are (literally) tens of thousands of entries doesn't seem to be efficient or practical - and likely to get me a slap on the wrist by the IT department.

So, given that an email address (which will look something similar to /O=MYCOMPANY/OU=EUROPE/CN=RECIPIENTS/CN=RICHARD), what is the best way to look up this contact on the GAL so that I can get hold of the "phone", "assistant", "title" and "mobile" fields?

I'm using Outlook 2003.

Richard
  • 1,371
  • 7
  • 21
  • 46

1 Answers1

0

I am not really up to speed on what you can do with the GAL, however, depending on how it's set up in your company you could try querying Active Directory instead for those fields. You can execute queries for specific users which would avoid having to effectively "download" the address book.

There's a lot of information on how to access it via VBA, plus some examples to get you started at http://www.rlmueller.net/ADOSearchTips.htm

i_saw_drones
  • 3,398
  • 1
  • 26
  • 48