Print a list of Outlook Categories and their Colors using VBA
Having a list of categories names and their colors can be helpful when sharing categories with other users, since the color is per-user.
Fortunately,MSDNpublished a sample macro that prints a list of categories and the name of the color assigned. Unfortunately, some of the color names in their macro are not valid. Below is the code fromCategory.Color Property (Outlook), with the correctedolCategoryColornames.
This macro can display a message box with a list of the category names and colors or print it to theVBA Editor‘sImmediatewindow.UseMsgBox strOutputto display a message box orDebug.Print strOutputto print a list to theImmediatewindow (ViewImmediatewindow orCtrl+G). You can copy the list from theImmediatewindow or theMsgBox.The printout and message box will look like the following:
Utility: Purple
Bookkeeping: Unknown
Business: Peach
Important: Dark Yellow
Test: Purple
Blue Category: Blue
Federal Holidays: Green
Needs Done: Dark Green
Old Projects that need finished: Dark Olive
Send Message: Yellow
Slipstick: Olive
Follow up soon: Dark Orange
List Category Colors Macro
To use, Open the VBA editor usingAlt+F11, right click on the Project folder and chooseInsert > Module. Paste this code into the module then click theRunbutton or pressF8. PressCtrl+Gto see the list of category names and colors in the immediate window.Comment out theMsgBoxline to use only the Immediate window.
Public Sub ListCategoryNamesandColors()Dim objNameSpace As NameSpace
Dim objCategory As Category
Dim strOutput As String
Set objNameSpace = Application.GetNamespace(“MAPI”)
If objNameSpace.Categories.Count > 0 Then
For Each objCategory In objNameSpace.Categories
strOutput = strOutput & objCategory.Name
Select Case objCategory.Color
Case OlCategoryColor.olCategoryColorNone
strOutput = strOutput & “: No color (white)” & vbCrLf
Case OlCategoryColor.olCategoryColorBlack
strOutput = strOutput & “: Black ” & vbCrLf
Case OlCategoryColor.olCategoryColorBlue
strOutput = strOutput & “: Blue” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkBlue
strOutput = strOutput & “: Dark Blue” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkGreen
strOutput = strOutput & “: Dark Green” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkMaroon
strOutput = strOutput & “: Dark Maroon” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkOlive
strOutput = strOutput & “: Dark Olive” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkOrange
strOutput = strOutput & “: Dark Orange” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkPeach
strOutput = strOutput & “: Dark Peach” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkPurple
strOutput = strOutput & “: Dark Purple” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkRed
strOutput = strOutput & “: Dark Red” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkSteel
strOutput = strOutput & “: Dark Steel” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkTeal
strOutput = strOutput & “: Dark Teal” & vbCrLf
Case OlCategoryColor.olCategoryColorDarkYellow
strOutput = strOutput & “: Dark Yellow” & vbCrLf
Case OlCategoryColor.olCategoryColorGray
strOutput = strOutput & “: Gray” & vbCrLf
Case OlCategoryColor.olCategoryColorGreen
strOutput = strOutput & “: Green” & vbCrLf
Case OlCategoryColor.olCategoryColorMaroon
strOutput = strOutput & “: Maroon” & vbCrLf
Case OlCategoryColor.olCategoryColorOlive
strOutput = strOutput & “: Olive” & vbCrLf
Case OlCategoryColor.olCategoryColorOrange
strOutput = strOutput & “: Orange” & vbCrLf
Case OlCategoryColor.olCategoryColorPeach
strOutput = strOutput & “: Peach” & vbCrLf
Case OlCategoryColor.olCategoryColorPurple
strOutput = strOutput & “: Purple” & vbCrLf
Case OlCategoryColor.olCategoryColorRed
strOutput = strOutput & “: Red” & vbCrLf
Case OlCategoryColor.olCategoryColorSteel
strOutput = strOutput & “: Steel” & vbCrLf
Case OlCategoryColor.olCategoryColorTeal
strOutput = strOutput & “: Teal” & vbCrLf
Case OlCategoryColor.olCategoryColorYellow
strOutput = strOutput & “: Yellow” & vbCrLf
Case Else
strOutput = strOutput & “: Unknown” & vbCrLf
End Select
Next
End If
‘ Display the output string in a msgbox
‘ or in the immediate window
MsgBox strOutput
Debug.Print strOutput
Set objCategory = Nothing
Set objNameSpace = Nothing
End Sub
Note
The message box is copyable – click in the text and pressCtrl+Cto copy it.
Data: 19/06/2013 Page:1
Total Chars: 3781Total Words: 609
File Size: 79 KB