Applies to: Microsoft Outlook 2013, Outlook 2010, Outlook 2007
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
Next
End If
' Print the list to the Immediate Window
' Press Ctrl+G to open it or use View > Immediate Window
Debug.Print strOutput
' 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
Public Sub RestoreCategories()
AddCategory "category", 17, 0
End Sub
Private Sub AddCategory()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
objNS.Categories.Add strCategoryName, intColor, intKey
Set objNS = Nothing
End Sub
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



