• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create a List of Color Categories to Merge or Restore

Slipstick Systems

› Developer › Create a List of Color Categories to Merge or Restore

Last reviewed on June 11, 2021     32 Comments

Applies to: Outlook (classic), Outlook 2010, Outlook 365 (Win)

The code samples on this page will get the category names, color, and shortcuts assigned. Once you have this list, you can use the second code sample to restore the list to a different computer. If you want a simple list of your categories and color names that are assigned, see Print a list of Outlook Categories and their Colors. For a list of utilities you can use to manage your color categories, see the Tools section at Outlook Categories and Color Categories.

Step 1: Get a formatted list of color categories.
Step 2: Add the formatted list to the AddCategory Macro and run the macro

Begin by running the GetCategoryNames macro. Press Ctrl+G to open the Immediate window then select all and copy the list. Paste the list into Notepad or a plain text email message.

If the categories names are not unique, the macro AddCategory macro will fail. You can use the DeleteCategories macro to remove all categories before adding your list of categories

Run the macro to create a formatted list of color categories

 

Private Sub GetCategoryNames()
    Dim objNS As NameSpace
    Dim objCat As Category
    Dim strOutput As String
    
    Set objNS = Application.GetNamespace("MAPI")
    
    If objNS.Categories.Count > 0 Then
        
        For Each objCat In objNS.Categories
           strOutput = strOutput & "AddCategory """ & objCat.Name & """, " _
           & objCat.Color & ", " & objCat.ShortcutKey & vbCrLf

' to remove categories as you make a list
' uncomment this line
'objNS.Categories.Remove (objCat.CategoryID)
        Next
    End If
    
    ' Print the list to the Immediate Window
    ' Press Ctrl+G to open it or use View > Immediate Window
   Debug.Print strOutput

'if you have a lot of categories, the immediate window won't be sufficient       
       Open "C:\mycategories.txt" For Append As 1
       Print #1, strOutput
       Close #1
    
    ' Clean up.
 Set objCat = Nothing
 Set objNS = Nothing
End Sub

 

Restore the color categories list

Copy the list created by the code above and paste it into this code sample, in place of
AddCategory "category", 17, 0

Add the formatted list to the AddCategories macro and run it

Then run the RestoreCategories macro. The On Error Resume Next line will allow you to add a category list that includes categories already in your master category list, however, the category color won't be updated if the old categories aren't removed.

Public Sub RestoreCategories()

   AddCategory "category", 17, 0

End Sub

Private Sub AddCategory(strCategoryName As String, intColor As Integer, intKey As Integer)
    Dim objNS As NameSpace
 
    Set objNS = Application.GetNamespace("MAPI")
       On Error Resume Next
    objNS.Categories.Add strCategoryName, intColor, intKey
    Set objNS = Nothing
End Sub

Restore a text file

This version of RestoreCategories code will read the categories from a text file. You'll either need to edit the text file to remove AddCategory from each line and the quotes from around the category name or create a text file without them.

To create the text file without AddCategory or quotes around the name, change the strOutput line in the GetCategoryNames macro to this

strOutput = strOutput & objCat.name & "," _
           & objCat.Color & ", " & objCat.ShortcutKey & vbCrLf

Public Sub RestoreCategories()
Dim objNS As NameSpace
Dim FileNum As Integer
Dim current_cat As String
Dim splitCategory() As String
    
Set objNS = Application.GetNamespace("MAPI")
  On Error Resume Next

FileNum = FreeFile()
Open "C:\mycategories.txt" For Input As #FileNum

While Not EOF(FileNum)
  Line Input #FileNum, current_cat
   splitCategory = Split(current_cat, ",")

' use text file, no quotes around name
objNS.Categories.Add splitCategory(0), splitCategory(1), splitCategory(2)
Wend
Close FileNum

End Sub

VBScript version to add categories

This is a VBScript version of the macro above.

Dim objOutlook, objNS, objFolder
Set objOutlook = CreateObject("Outlook.Application")
Set objNS = objOutlook.GetNamespace("MAPI")
Dim get_cat
Dim splitCategory
 
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\Documents\categories.txt",1)
do while not objFileToRead.AtEndOfStream
get_cat= objFileToRead.ReadLine()
splitCategory = Split(get_cat, ",")
'If already exists, skip 
On Error Resume Next 
' use text file, no quotes around category name
objNS.Categories.Add splitCategory(0), splitCategory(1), splitCategory(2)
loop
objFileToRead.Close
Set objFileToRead = Nothing

Using the GetCategoryNames and RestoreCategories Macros

The following video tutorial shows how to use the two macros above to create a list of your categories and their color then add those categories to Outlook. You can use these macros to share category names and colors with other Outlook users.

 

Delete color categories

To delete the existing categories and add the categories in your list, paste the following code into the VBA editor and add DeleteCategories as the first line of the RestoreCategories procedure:

Public Sub RestoreCategories()
   DeleteCategories
   AddCategory "category", 17, 0
End Sub

Warning: using the DeleteCategories procedure will delete all categories from the list.

Private Sub DeleteCategories()
    Dim objNS As NameSpace
    Dim objCat As Category
   
    Set objNS = Application.GetNamespace("MAPI")
   
    If objNS.Categories.Count > 0 Then
       
        For Each objCat In objNS.Categories
            objNS.Categories.Remove (objCat.CategoryID)
        Next
       
    End If
       
    Set objCat = Nothing
    Set objNS = Nothing
   
End Sub

While I recommend using the RestoreCategories code if you need to work with a lot of categories, if you want to add or remove a single category within a macro, you can do it with one line (for each action and category).

If you need to change the category color, you'd first remove it then add it back. The categories already assigned are not affected, the category is removed only from the master category list.

Sub AddRemoveCategories()
    Session.Categories.Remove ("Category2")
    Session.Categories.Add "Category2", 13, 0
End Sub

Get the Categories from All Mailboxes in Profile

This code sample reads every data file in an Outlook profile and grabs the category names, colors and shortcut key, writing the lists to the Immediate window (Ctrl+G) in the format needed by the restore categories macro.

Private Sub GetCategoryNamesinAllAccounts()
    Dim oStores As Outlook.Stores
    Dim oStore As Outlook.Store
    Dim oCategories As Outlook.Categories
    Dim oCategory As Outlook.Category
    Dim strOutput As String
    
    Set oStores = Application.Session.Stores
 
    For Each oStore In oStores
        Set oCategories = oStore.Categories

        If oCategories.Count > 0 Then
        For Each oCategory In oCategories
             strOutput = strOutput & "AddCategory """ & oCategory.Name & """, " _
           & oCategory.Color & ", " & oCategory.ShortcutKey & vbCrLf
        Next
        End If
     
        strOutput = oStore.DisplayName & vbCrLf _
        & "--------------Categories-----------------" & vbCrLf _
        & strOutput
        Debug.Print strOutput

'if you have a lot of categories, the immediate window won't be sufficient       
       Open "C:\mycategories.txt" For Append As 1
       Print #1, strOutput
       Close #1
 
       strOutput = ""

    Next

 Set oStores = Nothing
 Set oStore = Nothing
 Set oCategories = Nothing
 Set oCategory = Nothing
 
End Sub

Set Uniform Categories on All Accounts in Profile

By putting the macros above together, you can create a macro that reads all categories in all accounts in the profile, saving them to a text file, then imports a list of categories to all accounts. In addition, if you need some categories unique to an account, you can set an If statement and add categories only to that account.

Because all of the code needed to do this is listed above (in the Get the Categories from All Mailboxes and RestoreCategories macros), I'm only going to link to a text file containing the macro.

Copy and paste the code into a module, then run the GetCategoryNamesinAllAccounts macro which creates a text file containing all of the category names. You can clean up this list in Excel - paste it into Excel then sort and delete duplicate categories.

After the list is cleaned up, paste it in the AddCategoriesToAllStores macro and run it.

set-uniform-categories

 

Category Colors by number

The following is a list of the category colors and their index number. Outlook 365 has brighter colors and some new color names, which are noted in the table.

ColorIndexColorIndex
Red1New: Gray
Old: Dark Gray
14
Orange2New: Dark Gray
Old: Black
15
Peach3Dark Red16
Yellow4Dark Orange17
New: Light Green
Old: Green
5New: Brown
Old: Dark Peach
18
New: Light Teal
Old: Teal
6New: Gold
Old: Dark Yellow
19
New: Lime Green
Old: Olive
7Dark Green20
Blue8New: Teal
Old: Dark Teal
21
New: Lavender
Old: Purple
9New: Green
Old: Dark Olive
22
New: Magenta
Old: Maroon
10New: Navy Blue
Old: Dark Blue
23
New: Light Gray
Old: Steel
11Dark Purple24
New: Steel
Old: Dark Steel
12New: Dark Pink
Old: Dark Maroon
25
New: Warm Gray
Old: Gray
13
Create a List of Color Categories to Merge or Restore was last modified: June 11th, 2021 by Diane Poremsky

Related Posts:

  • Use VBScript to Export or Import Categories
  • Print a list of Outlook Categories and their Colors
  • Use PowerShell to Export and Import Categories
  • Use Upgrade to Color Categories to add Categories to the Master List

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
32 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

AaronT
September 22, 2021 12:26 pm

Hello Diane,

I am dipping my toes into scripting for for Outlook 365 and stumbled across your feeds. They have been very helpful in giving me a baseline to start from. I am trying to create a simple process for my team to use for time tracking and wanted to leverage Outlook meetings and assigned Categories. Would you happen to have a sample script that can return what categories are assigned to a selected Outlook Meeting? My vision is to create a form that pops up and allows people to select/change categories for meetings. We want to make applying categories easier with a form as we have separate groups for the categories (e.g. Group 1 is customer, Group 2 is Country, Group 3 is Internal Tracking, etc...) and people don't like scrolling through the category list. Any help or guidance would be greatly appreciated.

0
0
Reply
Jenny Hutchison
March 17, 2020 3:52 pm

Thank you very much for this clear, comprehensive, and sanity-saving information. Saved me from hours of work, after a company update took apart my categorisation.

0
0
Reply
Greg
March 21, 2019 6:59 pm

Thanks! This is exactly what I have been looking for. I have a lot of categories and I work on multiple computers. I've been looking for a way to keep them in sync.

Is it possible to have the restore code read the list from the file it saved instead of having to open the editor and paste it in each time?

0
0
Reply
Diane Poremsky
Author
Reply to  Greg
March 26, 2019 1:07 am

Yes it is. I don't have code handy to do it (i have some i think might work, but i haven't tested it). I'll try to check it tomorrow and post it.

0
0
Reply
Diane Poremsky
Author
Reply to  Greg
March 28, 2019 8:04 am

Ok - i added a sample that loads the text file. You need to create a text file without AddCategories or quotes or use find and replace to remove them from an existing text file.

0
0
Reply
Greg
Reply to  Diane Poremsky
March 28, 2019 10:54 am

Thanks! I'll give it a try sometime in the next few days. This should make it much easier to keep my categories in sync. I have the category file going to cloud storage so whenever I add/change/delete categories it should be as simple as running the GetCategoryNameswhere I made the change and then RestoreCategories on the other machines.

0
0
Reply
Terje Bronebakk
December 14, 2016 8:11 am

I have two inboxes on my Outlook. Have managed to extract the list of categories from the original inbox. But when trying to install this list on the new inbox I can't make it do that. It always does the restore to the original inbox.
Have the new inbox as master, but still will not do it. Any tricks?

Terje

1
0
Reply
Pandu
October 4, 2016 1:03 pm

Hi Diana,
I have an appointment item open and I set custom color categories and show a msgbox (to check whether to send the meeting request or not, based on the timings - on send click).

When I click on No - the meeting request will not be sent and say red color category is shown. Now I have selected other timings which is still not good time for a meeting, so yellow color category shows.
Expected output, Red color category should be removed from the meeting item and only Yellow should show but, the issue is, both Red and yellow color categories are shown. I checked in debug mode the Item category is shown as empty

I tried removing the categories but it is not removing the current session already aligned category:

Dim category
For Each category In Session.Categories

If (category = "") Then
Session.Categories.Remove ("X")
End If
Next

How can we do this? Appreciate the quick help on this.

0
0
Reply
Lane
May 19, 2016 5:05 pm

Diane,

If I wanted to use this on a shared folder, what are some possibilities to have it grab it from there?
Thanks

0
0
Reply
Diane Poremsky
Author
Reply to  Lane
August 14, 2016 2:23 pm

I'm not sure if you could make it work with this - https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#shared.

0
0
Reply
Mike C
February 19, 2016 7:49 pm

Hi, I use categories on my Contacts - I just upgraded to Outlook 2016 - and while all my Categories are still there against the various Contacts the master list of categories and their colours etc have vanished... Is there a way to backwards engiuneer the categories from the contact list...

0
0
Reply
Diane Poremsky
Author
Reply to  Mike C
February 19, 2016 8:02 pm

The category colors are stored on the default data file. Did your profile change? Right click on the top level folder (usually is your email address) and choose properties. Them click the upgrade to color catergores button - the should add the categories to the master list, and assign colors, although the colors wont be the same as before.

0
0
Reply
Simou2
Reply to  Mike C
May 21, 2016 1:27 am

If you get is "not in master...." you can click on it and highlight it then click "NEW" this should bring up the New Categories Whit the name of the that one missed colored then select the color you like and save/add it, this should make all other with the same category change to that color.
When moving to a new computer it dose not have the same Index categories list as the old computer this is why that it is not in the Master list, i'm not good at code so i when though and did this for each old Category i had

hope this helps you, and you can under stand my instructions

0
0
Reply
Julian Wattam
April 9, 2015 11:19 am

I think I did mess about with calendar subs once. Maybe if I have a dig around in Outlook's settings I'll find the leftover bits and won't need the on error...

I used ucase because I'm not sure if the way I see it is the way others see it, ie whether it's in my Outlook profile or comes from the Exchange server. I tend to capitalise on any comparison just in case. It would be just my luck that IT do something that changes the presentation of the address and break my code!

Thanks again.

0
0
Reply
Webmaster
Reply to  Julian Wattam
April 9, 2015 2:40 pm

The shared mailbox names come from the Exchange server (as does your own display name) so everyone should see the same thing.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 32

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment