• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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

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?

  • 2
1 Solution
did you check script center at microsoft technet site ?
jwolterAuthor Commented:
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now