Class Category (Outlook VBA)

The class Category represents a user-defined category by which Outlook items can be grouped. To use a Category class variable it first needs to be instantiated, for example


Dim ctg as Category
Set ctg = Session.DefaultStore.Categories(Index:=1)

For Each

Here is an example of processing the Category items in a collection.


Dim ctg As Category
For Each ctg In Session.DefaultStore.Categories
	
Next ctg

CategoryBorderColor

Returns an OLE_COLOR value that represents the border color of the color swatch displayed for a Category object.

Setting the Color property of the Category object to an OlCategoryColor constant changes the value of this property, as well as the value of the CategoryGradientBottomColor and CategoryGradientTopColor properties. This color should be used to display the border of a gradient-shaded color swatch for the Category object.


Dim varCategoryBorderColor As Variant
varCategoryBorderColor = Session.DefaultStore.Categories(1).CategoryBorderColor

CategoryGradientBottomColor

Returns an OLE_COLOR value that represents the bottom gradient color of the color swatch displayed for a Category object.

Setting the Color property of the Category object to an OlCategoryColor constant changes the value of this property, as well as the value of the CategoryGradientTopColor and CategoryBorderColor properties. This color should be used to display a gradient-shaded color swatch for the Category object.


Dim varCategoryGradientBottomColor As Variant
varCategoryGradientBottomColor = Session.DefaultStore.Categories(1).CategoryGradientBottomColor

CategoryGradientTopColor

Returns an OLE_COLOR value that represents the top gradient color of the color swatch displayed for a Category object.

Setting the Color property of the Category object to an OlCategoryColor constant changes the value of this property, as well as the value of the CategoryGradientBottomColor and CategoryBorderColor properties. This color should be used to display a gradient-shaded color swatch for the Category object.


Dim varCategoryGradientTopColor As Variant
varCategoryGradientTopColor = Session.DefaultStore.Categories(1).CategoryGradientTopColor

CategoryID

Returns a String value that represents the unique identifier for the Category object.

Because the Name property of a Category object can be changed either programmatically or by user action, each Category object is uniquely identified by a globally unique identifier (GUID), assigned to the object, that can be retrieved using this property. The GUID is presented as a string using the following format:


{00000000-0000-0000-0000-000000000000}

Class

Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for OlObjectClass.


Dim oocsClass As OlObjectClass
oocsClass = Session.DefaultStore.Categories(1).Class

Color

Returns or sets an OlCategoryColor constant that indicates the color used by the Category object. Here you can find possible values for OlCategoryColor.

You can share the same color for multiple categories, by specifying the same constant that represents the category color in the OlCategoryColor enumeration for those Category objects.


Private Sub ListCategoryColors() 
 Dim objNameSpace As NameSpace 
 Dim objCategory As Category 
 Dim strOutput As String 
 
 ' Obtain a NameSpace object reference. 
 Set objNameSpace = Application.GetNamespace("MAPI") 
 
 ' Check if the Categories collection for the Namespace 
 ' contains one or more Category objects. 
 If objNameSpace.Categories.Count > 0 Then 
 
 ' Enumerate the Categories collection, checking 
 ' the value of the Color property for 
 ' each Category object. 
 For Each objCategory In objNameSpace.Categories 
 
 ' Add the name of the Category object to 
 ' the output string. 
 strOutput = strOutput & objCategory.Name 
 
 ' Add information about the assigned color 
 ' to the output string. 
 Select Case objCategory.Color 
 Case OlCategoryColor.olCategoryColorNone 
 strOutput = strOutput & ": No color" & vbCrLf 
 Case OlCategoryColor.olCategoryColorBlack 
 strOutput = strOutput & ": Black " & vbCrLf 
 Case OlCategoryColor.olCategoryColorBlue 
 strOutput = strOutput & ": Blue" & vbCrLf 
 Case OlCategoryColor.olCategoryColorGray 
 strOutput = strOutput & ": Gray" & vbCrLf 
 Case OlCategoryColor.olCategoryColorGreen 
 strOutput = strOutput & ": Green" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightBlue 
 strOutput = strOutput & ": Light blue" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightGray 
 strOutput = strOutput & ": Light gray" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightGreen 
 strOutput = strOutput & ": Light green" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightMaroon 
 strOutput = strOutput & ": Light maroon" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightOlive 
 strOutput = strOutput & ": Light olive" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightOrange 
 strOutput = strOutput & ": Light orange" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightPeach 
 strOutput = strOutput & ": Light peach" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightPurple 
 strOutput = strOutput & ": Light purple" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightRed 
 strOutput = strOutput & ": Light red" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightSteel 
 strOutput = strOutput & ": Light steel" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightTeal 
 strOutput = strOutput & ": Light teal" & vbCrLf 
 Case OlCategoryColor.olCategoryColorLightYellow 
 strOutput = strOutput & ": Light yellow" & 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. 
 MsgBox strOutput 
 
 ' Clean up. 
 Set objCategory = Nothing 
 Set objNameSpace = Nothing 
 
End Sub

Name

Returns or sets a String value that represents the display name for the object.


Session.DefaultStore.Categories(1).Name =

Session

Returns the NameSpace object for the current session.

The Session property and the GetNamespace method can be used interchangeably to obtain the NameSpace object for the current session. Both members serve the same purpose. For example, the following statements perform the same function:

ShortcutKey

Returns or sets an OlCategoryShortcutKey constant that specifies the shortcut key used by the Category object. Here you can find possible values for OlCategoryShortcutKey.

Any OlCategoryShortcutKey constant other than olCategoryShortcutKeyNone can only be used by one Category object at any given time. Setting the value of this property to an OlCategoryShortcutKey constant already in use sets the ShortcutKey property of the Category object already using the specified value to olCategoryShortcutKeyNone.


Private Sub ListShortcutKeys() 
 
 Dim objNameSpace As NameSpace 
 
 Dim objCategory As Category 
 
 Dim strOutput As String 
 
 
 
 ' Obtain a NameSpace object reference. 
 
 Set objNameSpace = Application.GetNamespace("MAPI") 
 
 
 
 ' Check if the Categories collection for the Namespace 
 
 ' contains one or more Category objects. 
 
 If objNameSpace.Categories.Count > 0 Then 
 
 
 
 ' Enumerate the Categories collection, checking 
 
 ' the value of the ShortcutKey property for 
 
 ' each Category object. 
 
 For Each objCategory In objNameSpace.Categories 
 
 
 
 ' Add the name of the Category object to 
 
 ' the output string. 
 
 strOutput = strOutput & objCategory.Name 
 
 
 
 ' Add information about the assigned shortcut key 
 
 ' to the output string. 
 
 Select Case objCategory.ShortcutKey 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyNone 
 
 strOutput = strOutput & ": No shortcut key" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF2 
 
 strOutput = strOutput & ": Ctrl+F2" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF3 
 
 strOutput = strOutput & ": Ctrl+F3" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF4 
 
 strOutput = strOutput & ": Ctrl+F4" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF5 
 
 strOutput = strOutput & ": Ctrl+F5" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF6 
 
 strOutput = strOutput & ": Ctrl+F6" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF7 
 
 strOutput = strOutput & ": Ctrl+F7" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF8 
 
 strOutput = strOutput & ": Ctrl+F8" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF9 
 
 strOutput = strOutput & ": Ctrl+F9" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF10 
 
 strOutput = strOutput & ": Ctrl+F10" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF11 
 
 strOutput = strOutput & ": Ctrl+F11" & vbCrLf 
 
 Case OlCategoryShortcutKey.olCategoryShortcutKeyCtrlF12 
 
 strOutput = strOutput & ": Ctrl+F12" & vbCrLf 
 
 Case Else 
 
 strOutput = strOutput & ": Unknown" & vbCrLf 
 
 End Select 
 
 Next 
 
 End If 
 
 
 
 ' Display the output string. 
 
 MsgBox strOutput 
 
 
 
 ' Clean up. 
 
 Set objCategory = Nothing 
 
 Set objNameSpace = Nothing 
 
 
 
End Sub