Outlook - Deleting a Category from Contacts

Posted on 2011-09-02
Medium Priority
Last Modified: 2012-08-13
Looking for someone willing to right a script that can detect all contacts with a certain category, remove and replce the catagory in all the contact records.
Question by:afreestyle
  • 2
  • 2
LVL 93

Accepted Solution

Patrick Matthews earned 2000 total points
ID: 36475798
The following works in Outlook 2007.

It's a bit tricky: Outlook stores category assignments as a comma delimited list, so you have to be very careful about doing the replacements.

Sub ReplaceCategory()
    Dim fld As Folder
    Dim it As Object
    Dim Counter As Long
    Const OldCat = "Foo"
    Const NewCat = "Hee"
    Set fld = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
    For Each it In fld.Items
        If it.Class = olContact Then
            If InStr(1, ", " & it.Categories & ", ", ", " & OldCat & ", ") > 0 Then
                If it.Categories Like OldCat & ", *" Then
                    it.Categories = Replace(it.Categories, OldCat, NewCat, 1, 1)
                ElseIf it.Categories Like "*, " & OldCat Then
                    it.Categories = Left(it.Categories, Len(it.Categories) - Len(OldCat)) & NewCat
                    it.Categories = Replace(it.Categories, ", " & OldCat & ", ", ", " & NewCat & ", ")
                End If
                Counter = Counter + 1
            End If
        End If
    MsgBox "Done; " & Counter & " contacts updated"
End Sub

Open in new window


Author Comment

ID: 36475811
Thank you for the quick responce. Could you possibly add a quick blub on how to run this?
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 2000 total points
ID: 36475870
From Outlook, hit Alt+F11 to get t the VB Editor.

Insert a new module, and paste my code in there.  Modify the contants for the old category and the new category.  To run it, hit F5 in the VB Editor, or Alt+F8 from Outlook.

Author Comment

ID: 36475946
Am I missing a step?

Everything seems to function, but when I go look at the contact it is still categorised as Foo.


Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I came across an unsolved Outlook issue and here is my solution.
After a recent Outlook migration from a 2007 to 2010 environment, some issues with Distribution List owners were realized. In this article, I explain how that was rectified.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

607 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