Categories Object (Outlook)

Represents the collection of Category objects that define the Master Category List for a namespace.

Version Information

Version Added: Outlook 2007

Remarks

Microsoft Outlook provides a categorization system by which Outlook items can be easily identified and grouped into user-defined categories. The Categories object represents the set of user-defined categories available to the user of a given mailbox.

Use the Categories property of the NameSpace object to obtain a Categories object reference, representing the Master Category List for that namespace.

Use the Add method to create a new Category object and append it to the collection. Use the Item method to obtain a Category object reference for an existing category, and the Remove method to remove a Category object from the collection. Use the Count property to return the number of categories contained in the collection.

Example

The following Visual Basic for Applications (VBA) example displays a dialog box containing the names and identifiers for each Category object contained in the Categories collection associated with the default NameSpace object.

Private Sub ListCategoryIDs() 
 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. 
 For Each objCategory In objNameSpace.Categories 
 
 ' Add the name and ID of the Category object to 
 ' the output string. 
 strOutput = strOutput & objCategory.Name & _ 
 ": " & objCategory.CategoryID & vbCrLf 
 Next 
 End If 
 
 ' Display the output string. 
 MsgBox strOutput 
 
 ' Clean up. 
 Set objCategory = Nothing 
 Set objNameSpace = Nothing 
 
End Sub 

See Also

Concepts

Categories Object Members

Outlook Object Model Reference