Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Outlook - Deleting a Category from Contacts

Posted on 2011-09-02
4
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 93

Accepted Solution

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

722 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