How to Batch Remove Deleted Color Categories from All Outlook Items

After you delete a color category, it will still display in the Outlook items, which you have assigned the category to. This post will teach you how to quickly remove such color categories from Outlook items.

Outlook permits users to add and delete color categories at will. However, though you delete a color category, if you have assigned it to many Outlook items before, this color category will not be removed from the items accordingly. Now that you have deleted this color category, which means that it is useless, why not remove it from the Outlook items as well? Now, in the followings, we’ll teach you a quick method to realize it.

Batch Remove Deleted Color Categories from All Outlook Items

Batch Remove Deleted Color Categories from All Outlook Items

  1. At the very outset, start your Outlook application as usual.
  2. Then, after accessing the main Outlook window, you can press the “Alt + F11” key buttons, which will bring up the “Microsoft Visual Basic for Applications” window.
  3. In the new screen, you need to find and open an unused module.
  4. Next, copy the following VBA code into this module.
Dim objSourceStore As Outlook.Store
Dim strMasterCategoryList As String

Sub DeleteAllColorCategories_ThatAreNotInMasterCategoryList()
    Dim objSourcePSTFile As Outlook.Folder
    Dim objFolder As Outlook.Folder
    'Specify the source Outlook PST file
    Set objSourceStore = Application.Session.Stores.Item("John Smith")
    'Get all color categories of this PST file
    For Each objCategory In objSourceStore.Categories
        strMasterCategoryList = objCategory.Name & ", " & strMasterCategoryList
    Set objSourcePSTFile = Outlook.Application.Session.folders("John Smith")
    For Each objFolder In objSourcePSTFile.folders
        Call ProcessFolders(objFolder)
End Sub

Sub ProcessFolders(ByVal objCurrentFolder As Outlook.Folder)
    Dim objVariant As Variant
    Dim strCategories As String
    Dim varArray As Variant
    Dim i, n As Long

    For i = objCurrentFolder.Items.count To 1 Step -1
        Set objVariant = objCurrentFolder.Items.Item(i)
        If objVariant.Categories <> "" Then
           strCategories = objVariant.Categories
           'Get all color categories of this item
           varArray = Split(objVariant.Categories, ",")
           For n = 0 To UBound(varArray)
               'Check if each color category of this item is in master category list
               If InStr(1, strMasterCategoryList, Trim(varArray(n))) = 0 Then
                  'If not, remove this category
                  Call RemoveCategory(objVariant, varArray(n))
              End If
          Next n
       End If
    Next i
    'Process all subfolders recursively
    If objCurrentFolder.folders.count > 0 Then
       For Each objSubfolder In objCurrentFolder.folders
           Call ProcessFolders(objSubfolder)
    End If
End Sub

Sub RemoveCategory(objCurrentItem, strCategory)
    Dim varNewArray As Variant
    varNewArray = Split(objCurrentItem.Categories, ",")
    If UBound(varNewArray) >= 0 Then
       For i = 0 To UBound(varNewArray)
           'Find the specific color category
           If Trim(varNewArray(i)) = strCategory Then
              'Delete it from this item
              varNewArray(i) = ""
              'Rebuild the color categories of this item
              objCurrentItem.Categories = Join(varNewArray, ",")
              Exit Sub
           End If
    End If
End Sub

VBA Code - Batch Remove Deleted Color Categories from All Outlook Items

  1. After that, you should change your Outlook macro security level to low.
  2. Eventually, you can run this macro. Just press F5 key in this macro screen or click the “Run” icon in the toolbar.
  3. After the macro finishes running, you’ll see that all the color categories which are have been deleted have been removed from Outlook items.

Outlook Is Prone to Corruption

If you are a regular user of Outlook, maybe you’ve encountered a variety of issues in your Outlook. In general, to fix the small errors involving PST file, you can just recur to the inbuilt fix utility – Scanpst. But, if you suffer serious troubles, such as severely compromised PST file, you have no choice but to take aid of an external potent tool, like DataNumen Outlook Repair.

Author Introduction:

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

Leave a Reply

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