Solved

Outlook - Deleting a Category from Contacts

Posted on 2011-09-02
4
413 Views
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.
0
Comment
Question by:afreestyle
  • 2
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 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
                Else
                    it.Categories = Replace(it.Categories, ", " & OldCat & ", ", ", " & NewCat & ", ")
                End If
                it.Save
                Counter = Counter + 1
            End If
        End If
    Next
    
    MsgBox "Done; " & Counter & " contacts updated"
    
End Sub

Open in new window

0
 

Author Comment

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

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 500 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.
0
 

Author Comment

by:afreestyle
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.

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

821 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