Class Categories (Outlook VBA)
The class Categories represents the collection of Category objects that define the Master Category List for a namespace. To use a Categories class variable it first needs to be instantiated, for example
Dim ctgs as Categories
Set ctgs = Session.DefaultStore.Categories
For Each
Here is an example of processing the Categories items in a collection.
Dim ctg As Category
For Each ctg In Session.DefaultStore.Categories
Next ctg
Add
Creates a new Category object and appends it to the Categories collection.
Add (Name, Color, ShortcutKey)
Dim strName As String: strName =
Dim ctg As Category
Set ctg = Session.DefaultStore.Categories.Add(Name:=strName)
Arguments
The following argument is required
Name (String) - The name of the new category.
Optional arguments
The following arguments are optional
Color (OlCategoryColor) - The color for the new category. If no value is specified, the new category is set to the first color (as specified in the order of the OlCategoryColor enumeration) that is the least used, That is, if there are unused colors, the new category is set to the first unused color in the OlCategoryColor enumeration. If all colors in the OlCategoryColor enumeration have been used, then the new category is set to the first color that is used least in the OlCategoryColor enumeration.
Here you can find possible values for
ShortcutKey (OlCategoryShortcutKey) - The shortcut key for the new category. If no value is specified, the default value is OlCategoryShortcutKeyNone.
Here you can find possible values for
Class
Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for
Dim oocsClass As OlObjectClass
oocsClass = Session.DefaultStore.Categories.Class
Count
Returns a Long value indicating the count of Category objects in the specified collection.
Dim lngCount As Long
lngCount = Session.DefaultStore.Categories.Count
Item
Returns a Category object from the collection.
If the name of a category is specified in Index, this method returns the first Category object that matches the specified value. If a match cannot be found, the method returns Null (Nothing in Visual Basic.)
Item (Index)
Index: Either a Long value representing the index number of the object, or a String value representing either the Name or CategoryID property value of an object in the collection.
Dim ctg As Category
Set ctg = Session.DefaultStore.Categories(Index:=1)
Remove
Removes an object from the collection.
If the name of a category is specified in Index, this method removes the first Category object that matches the specified value.
Remove (Index)
Index: Either a Long value representing the index number of the object, or a String value representing either the Name or CategoryID property value of an object in the collection.
Dim lngIndex As Long: lngIndex =
Session.DefaultStore.Categories.Remove Index:=lngIndex
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: