Link to home
Start Free TrialLog in
Avatar of jwolter
jwolter

asked on

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?

TIA,
John
Avatar of haim96
haim96

did you check script center at microsoft technet site ?
http://www.microsoft.com/technet/scriptcenter/default.mspx
ASKER CERTIFIED SOLUTION
Avatar of haim96
haim96

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jwolter

ASKER

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
             MyItem.Delete
          End If
        End If
      Next
      'MsgBox "Done!", 64, "Contact Tools Message"
   Else
      MsgBox "The current folder is not a Contact folder.", 64, "Contact" & _
      "Tools Message"
   End If
End Sub