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
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 SubRestore 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
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 SubRestore 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 SubWhile 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.
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.
| Color | Index | Color | Index |
|---|---|---|---|
| Red | 1 | New: Gray Old: Dark Gray | 14 |
| Orange | 2 | New: Dark Gray Old: Black | 15 |
| Peach | 3 | Dark Red | 16 |
| Yellow | 4 | Dark Orange | 17 |
| New: Light Green Old: Green | 5 | New: Brown Old: Dark Peach | 18 |
| New: Light Teal Old: Teal | 6 | New: Gold Old: Dark Yellow | 19 |
| New: Lime Green Old: Olive | 7 | Dark Green | 20 |
| Blue | 8 | New: Teal Old: Dark Teal | 21 |
| New: Lavender Old: Purple | 9 | New: Green Old: Dark Olive | 22 |
| New: Magenta Old: Maroon | 10 | New: Navy Blue Old: Dark Blue | 23 |
| New: Light Gray Old: Steel | 11 | Dark Purple | 24 |
| New: Steel Old: Dark Steel | 12 | New: Dark Pink Old: Dark Maroon | 25 |
| New: Warm Gray Old: Gray | 13 |


AaronT says
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.
Jenny Hutchison says
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.
Greg says
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?
Diane Poremsky says
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.
Diane Poremsky says
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.
Greg says
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.
Terje Bronebakk says
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
Pandu says
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.
Lane says
Diane,
If I wanted to use this on a shared folder, what are some possibilities to have it grab it from there?
Thanks
Diane Poremsky says
I'm not sure if you could make it work with this - https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#shared.
Mike C says
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...
Diane Poremsky says
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.
Simou2 says
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
Julian Wattam says
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.
Webmaster says
The shared mailbox names come from the Exchange server (as does your own display name) so everyone should see the same thing.
Julian Wattam says
I've had some problems with GetCategoryNamesinAllAccounts but I think I've kind of solved it. Not sure if part of the problem is my Outlook setup but I can't get it to run without hitting an automation error (or sometimes refers to a non-existent internet calendar sub?). I added a slightly lazy 'on error resume next' to avoid an error.
You used objCat but this was not defined - should be oCategory.
With the above tweaks, your code lists mailbox names but the categories are just those from my personal mailbox (which isn't even first on the list). It also stops before finishing. With my revised method below the next store is a personal folders file.
All I've done in my revised code is stepped back and replace oStore with oStores.item(i) which should surely produce the same result yet does not!
In my revised code I've got a line which outputs only the categories on the mailbox I'm interested in, which works, but run without this I notice that on some stores it is still reporting categories from my personal mailbox on some stores - perhaps because they're not compatible? There's a public folder for every mailbox, which is to do with our network. Maybe a further tweak can be added to ignore incompatible stores and remove the need for the error 'trap'.
Anyway, I'm getting what I need, so many thanks for your help. The only issue I have left is that the categories are not listed alphabetically - I'm guessing they are in order of creation.
Here's my tweaked version of your code:
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
On Error Resume Next
For i = 1 To oStores.Count
' If UCase(oStores.Item(i).DisplayName) = Remail Then 'use to find specific account - set Remail to required email address (upper case)
Set oCategories = oStores.Item(i).Categories
If oCategories.Count > 0 Then
For Each oCategory In oCategories
strOutput = strOutput & oCategory.Name & ", " _
& oCategory.Color & ", " & oCategory.ShortcutKey & vbCrLf
Next
End If
strOutput = oStores.Item(i).DisplayName & vbCrLf _
& "--------------Categories-----------------" & vbCrLf _
& strOutput
Debug.Print strOutput
strOutput = ""
' End If 'use with IF statement above
Next i
Set oStores = Nothing
Set oStore = Nothing
Set oCategories = Nothing
Set oCategory = Nothing
End Sub
Diane Poremsky says
>> You used objCat but this was not defined - should be oCategory
Oops. After I tested it, i decided to use the code from the other macros to create a list ready to import using the other code and swapped it out.
Did you previously have a calendar subscription? It sounds like the macro is seeing a data file that used to exist in the profile or exists in a different profile.
Diane Poremsky says
BTW, this line:
If UCase(oStores.Item(i).DisplayName) = Remail then
probably doesn't work because you aren't using the display name correctly or aren't setting it in the proper format. I personally would not use ucase - either use the display name as it appears or use lcase and set it on both the display name variable and on stores name.
This works here (shared mailboxes use the mailbox display name, not the email address).
If oStores.Item(i).DisplayName = "myaddress@mydomain.com" Then
Julian Wattam says
Thanks! I've since been trying to create a button to run a rule and hit the same problem - can only access rules in default mailbox. Hopefully the tweak for the category issue above will work with that too.
Diane Poremsky says
I added a macro to the end of the page that creates lists of each data file's category list.
Julian Wattam says
I used the first bit of code to interrogate the category list and it works great, except that it only works on my main mailbox. Is there a way to get it to look at another mailbox that's been added? I've got 6 email accounts in my profile. They're not set as 'send on behalf of' accounts if you know what I mean - not sure how else to express it. Thanks in advance!
Diane Poremsky says
It is, you need to get the data file id first - I'll see if i can put some code together.
Manzoor says
Thank you! It really worked.
Sheryl says
I wasn't using the macro picker for this. I was not able to run GetCategoryNames from the Immediate Window until I changed the declaration to public. My understanding is that "private" subroutines only can be called by the object or class.
My color specifications in the RestoreCategories subroutine were copied and pasted from the output of GetCategoryNames, as described in your article. They don't have the comment with the color name at the end (is there a list of numbers to colors somewhere?), but they are otherwise the same. Here is the first line:
AddCategory "Holiday", 6, 0
Perhaps the problem is in how I'm trying to use it. I created a Outlook.com "database" (I think it's an OST file) in Outlook, and copied my local calendar entries into it. I very much want to use the same colors in that calendar as the local calendar. The colors for each calendar are stored separately within that calendar's Registry entries (encrypted). There's nothing in the macro that specifies the calendar. Perhaps it's selecting the default calendar, and I haven't changed my default from the local calendar. I tried selecting the Outlook.com calendar then picking the RestoreCategories macro, but no joy.
Speaking of the Outlook.com calendar (as long as I have your attention), the synchronization problems are driving me crazy. I was able to get it to synchronize JUST ONCE by adding a category called "temp" to all the items, synching, then removing the "temp" category and synching again. 15 minutes or so later, a miracle - the calendar was on the Web. But since then, NOTHING has synched. The changes I make in the local Outlook.com calendar never get synched to the Web. Any thoughts on that?
Thanks for your help.
Diane Poremsky says
There is a list of color # at https://msdn.microsoft.com/en-us/library/office/bb208064(v=office.12).aspx - I'm not sure it's 100% accurate though, they had a lot of mistakes in the color names previously. It'll match most colors though.
Private subs can only be called from the module, not across modules. If you are pasting it in the VBA Editor then hitting run, private should work. You can call it from a macro in different module.
The code works on the default data file (store) - i don't have a code sample that works with other stores, but I do have one that gets the list of colors from all data stores.
Sub GetColorsAllDataFiles()
Set objStores = Application.Session.Stores
For Each objStore In objStores
Debug.Print vbCrLf & "----------------------------------------" & vbCrLf & objStore.DisplayName
Debug.Print "--------------Categories-----------------"
Set objCategories = objStore.Categories
For Each objCategory In objCategories
Debug.Print objCategory.Name & ", " & objCategory.Color & ", " & objCategory.ShortcutKey
Next
Next
End Sub
Sheryl says
Sorry, that's a just a fix for the first bug. Here's the fix for the second bug. (Doesn't anyone check the code before uploading?)
Change this line:
Private Sub AddCategory()
to this:
Private Sub AddCategory(strCategoryName As String, intColor As Integer, intKey As Integer)
This runs now without error, but it doesn't work as described. It seems to add categories okay (I think), but it doesn't reset the colors, which is why I wanted it. Oh well.
Diane Poremsky says
The necessary code depends on how you are using it. Private means it's not listed in the VBA macro picker - you need ot run it using other code or from the VBA editor. This is useful with code that is only used occasionally so it doesn't clutter up the macro list.
The colors are represented by the numbers and what is assigned to the category name should be used in outlook.
AddCategory "work", 17, 0 'orange
AddCategory "important", 3, 0 'peach
AddCategory "personal", 8, 0 'blue
would each use a different color.
Sheryl says
The first subroutine, GetCategoryNames(), should be PUBLIC, not PRIVATE. That is the problem.
oliver says
Private Sub AddCategory(strCategoryName As String, intColor As Integer, intKey As Integer)
Diane Poremsky says
BTW, this "Wrong number of arguments or invalid property assignment" likely means this line: AddCategory "category", 17, 0 is the problem. You need 3 arguments - the category name in quotes, the color number, and the shortcut code (0 for no shortcut).
Robert says
When I run the restore portion I get the error, compile error: Wrong number of arguments or invalid property assignment. Help please as the deleted portion has already worked properly and now I have no categories.
Diane Poremsky says
Are any of the lines in red?
Did you paste the list of categories in this code, each category is one per line.
Public Sub RestoreCategories()
AddCategory "category", 17, 0
End Sub