How to Quickly Delete the Unused Color Categories in Outlook

If you want to rapidly find out and delete the unused color categories, which are not assigned to any outlook items, you can utilize the VBA code introduced in this post.

To better manage your Outlook items, perhaps you’ve created many custom color categories. However, after a period of time, you may find some categories are not useful any longer. For instance, it has been a long time that some color categories haven’t been used for a long time. In this case, actually, it is suggested to remove these useless color categories. Now, we will share a piece of VBA code with you, which can help you quickly delete such color categories.

Quickly Delete the Unused Color Categories in Outlook

Quickly Delete the Unused Color Categories in Outlook

  1. At the very outset, launch your Outlook application.
  2. Then press “Alt + F11” key buttons in Outlook main window.
  3. Next in the subsequent “Microsoft Visual Basic for Applications” window, you can open an empty module or directly insert a new module.
  4. After that, you need copy and paste the following VBA code into this module.
Dim objDictionary As Object
 
Sub DeleteColorCategories_NotAssigned2AnyItems ()
    Dim objStore As Outlook.Store
    Dim objCategories As Outlook.Categories
    Dim objCategory As Outlook.Category
    Dim objPSTFile As Outlook.Folder
    Dim objFolder As Outlook.Folder
    Dim varArrayKey As Variant
    Dim varArrayItem As Variant
    Dim i As Long
 
    Set objDictionary = CreateObject("Scripting.Dictionary")
 
    'Get the color categories of an Outlook mailbox
    'Change "johnsmith@datanumen.com" to your own mailbox name
    Set objStore = Application.Session.Stores.Item("johnsmith@datanumen.com")
    Set objCategories = objStore.Categories
    For Each objCategory In objCategories
        objDictionary.Add objCategory.Name, 0
    Next
 
    Set objPSTFile = objStore.GetRootFolder
    For Each objFolder In objPSTFile.folders
        ProcessFolder objFolder
    Next
 
    varArrayKey = objDictionary.Keys
    varArrayItem = objDictionary.Items
 
    'Delete the color categories not assigned to any outlook items
    For i = LBound(varArrayKey) To UBound(varArrayKey)
        If varArrayItem(i) = 0 Then
           objCategories.Remove (varArrayKey(i))
        End If
    Next
 
    MsgBox "Complete!", vbExclamation
End Sub
 
Sub ProcessFolder(ByVal objCurrentFolder As Object)
    Dim objItem As Object
    Dim objSubFolder As Object
    Dim varArrayCategories As Variant
    Dim varArrayCategory As Variant
 
    'Get the count of items under each color category
    For Each objItem In objCurrentFolder.Items
        If objItem.Categories <> "" Then
           varArrayCategories = Split(objItem.Categories, ",")
 
           For Each varArrayCategory In varArrayCategories
               If objDictionary.Exists(varArrayCategory) = True Then
                  objDictionary.Item(varArrayCategory) = objDictionary.Item(varArrayCategory) + 1
               End If
           Next
 
        End If
    Next
 
    'Process all subfolders recursively
    If objCurrentFolder.folders.count > 0 Then
       For Each objSubFolder In objCurrentFolder.folders
           ProcessFolder objSubFolder
       Next
    End If
End Sub

VBA Code - Delete the Unused Color Categories

  1. Subsequently, you should check your Outlook macro settings to insure that macros are permitted in your Outlook.
  2. Optionally, if you frequently require this feature, you can add the new macro to Quick Access Toolbar or ribbon.
  3. Eventually, you can take a shot. Just back to the new module window and hit the “run” icon in the toolbar to trigger this new macro.Run this Macro
  4. After this macro finishes, you can access your Color Categories list. You’ll see that all the unused color categories have been deleted.

Keep in Mind that Outlook Is Vulnerable

Outlook PST file is vulnerable to various factors, like email borne virus, malicious macros or improper shutting down. Thus, Outlook users should bear in mind this unquestioned fact. Therefore, some precautions are extremely essential, such as making regular backups and keeping a potent Outlook repair tool in vicinity 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 sql and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.