Outlook VBA (Address Book): A little help getting started

Posted on 2006-04-30
Last Modified: 2008-02-26
I'm in the process of migrating to Outlook from Palm Desktop and I have a problem requiring a little automation.  On PD, I had my company's entire phonebook as part of my address book.  All those addresses (over 1500 of 'em) were in a single category, so I could perform operations on the whole category, such as deleting them to make room for an update.

When I imported my PD address book into Outlook, all my categories were lost, so now I've got thousands of contacts of all sorts intermingled.  I'd like to separate out all the company ones based on a piece of text that is in the Address field of the Outlook contact.  I figure that VBA probably can do the job easily.  I'm very familar with VBA, being an old hand at Excel VBA, but I don't have a handle on the Outlook Object Model.

Could someone post a bit of code to get me going?

Question by:jwolter
    LVL 13

    Expert Comment

    did you check script center at microsoft technet site ?
    LVL 13

    Accepted Solution

    LVL 1

    Author Comment

    Okay, I've looked at the links and found some code to modify.  Here's what I ended up doing.  My original plan was just to assign all of the matches to a category, but instead, I deleted them.  Here's my code:

    Sub reaper()

    Dim MyItem As ContactItem
       'The following code only sorts contacts in the current folder by LastName, FirstName.
       Set CurFolder = Application.ActiveExplorer.CurrentFolder
       If CurFolder.DefaultItemType = 2 Then
          'MsgBox "This process may take some time. You will be notified" & _
          '" when complete.", , "Contact Tools Message"
          Set MyItems = CurFolder.Items
          For i = 1 To MyItems.Count
            Set MyItem = MyItems.Item(i)
            If UCase(Left(MyItem.MessageClass, 11)) = "IPM.CONTACT" Then
              ' Here's where we select the contacts to delete
              If Left(MyItem.BusinessAddress, 13) = "Supported Org" Then
              End If
            End If
          'MsgBox "Done!", 64, "Contact Tools Message"
          MsgBox "The current folder is not a Contact folder.", 64, "Contact" & _
          "Tools Message"
       End If
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
    Viewers will learn how to use the Hootsuite Dashboard.
    The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now