How to Batch Replace One Color Category with Another for All Outlook Items

If you want to replace one color category with another for all Outlook items, you must long for a way that allows you to achieve this in bulk, instead of manually doing it. Now, this article will show you such a method.

Have you ever wished to quickly replace one color category with another for all items in your Outlook? For example, if you want to abandon and delete a color category from your Outlook, you may want to replace it with another on all items before deleting. Without any doubts, it is quite troublesome to replace one by one. Thus, in the followings, we will introduce a smarter way.

Batch Replace One Color Category with Another for All Outlook Items

Batch Replace One Color Category with Another for All Items

  1. At the outset, launch Outlook application as usual.
  2. Then, in the main Outlook window, you need to press “Alt + F11” key buttons.
  3. Subsequently, you’ll enter “Microsoft Visual Basic for Applications” screen, in which you ought to open a module that is not in use.
  4. Next, you’d be required to copy and paste the following VBA code into such a module.
Dim strSourceCategory As String
Dim strTargetCategory As String

Sub BatchReplaceSpecificColorCategoryWithAnother_AllItems()
    Dim objOutlookFile As Outlook.folder
    Dim objFolder As Outlook.folder
 
    'Select a source Outlook File
    Set objOutlookFile = Application.Session.PickFolder
 
    If Not (objOutlookFile Is Nothing) Then
       'Change the following two lines as per your needs
       'Example: replace "Red Category" with "Green Category"
       strSourceCategory = "Red Category"
       strTargetCategory = "Green Category"
 
       For Each objFolder In objOutlookFile.folders
           Call ProcessFolders(objFolder)
       Next
 
       MsgBox "Complete!", vbExclamation
    End If
End Sub

Sub ProcessFolders(ByVal objCurrentFolder As Outlook.folder)
    Dim i, n As Long
    Dim objItem As Object
    Dim varArray As Variant
    Dim objSubfolder As Outlook.folder
 
    For i = objCurrentFolder.Items.count To 1 Step -1
        Set objItem = objCurrentFolder.Items(i)
        'Get the item's color categories
        varArray = Split(objItem.Categories, ",")
 
        If UBound(varArray) >= 0 Then
           For n = 0 To UBound(varArray)
               'Remove the source category
               If Trim(varArray(n)) = strSourceCategory Then
                  varArray(n) = ""
 
                  With objItem
                       .Categories = Join(varArray, ",")
                       'Assign the target category
                       .Categories = objItem.Categories & "," & strTargetCategory
                       .Save
                  End With
               End If
           Next
        End If
    Next i
 
    'Process all subfolders recursively
    If objCurrentFolder.folders.count > 0 Then
       For Each objSubfolder In objCurrentFolder.folders
           Call ProcessFolders(objSubfolder)
       Next
    End If
End Sub

VBA Code - Batch Replace One Color Category with Another for All Items

  1. After that, you could trigger this macro right now.
  2. Just press “F5” key button or click the “Run” icon in the toolbar in the current module screen.
  3. At once, you will be demanded to choose a source Outlook file whose items’ categories will be checked and replaced.
  4. Lastly, when the macro completes, you will get a prompt.
  5. Now, you can check all the items. You’ll find that the source color categories on items have been replaced by the target one, shown as the image below:Replaced Color Category

In the Event of Outlook Damage

Despite endowed with a host of excellent capabilities, Outlook is still vulnerable to various errors and corruption. Hence, you should make a regular data backup for your Outlook file. Besides, when confronted with unexpected Outlook crashes, you can first try inbox repair tool. If it fails, you can resort to a robust external tool like DataNumen Outlook Repair. It can fix Outlook issues in a jiffy.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover mdf and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *