Category Object

Outlook Developer Reference

Represents a user-defined category by which Outlook items can be grouped.

Version Information
 Version Added:  Outlook 2007

Remarks

Microsoft Office Outlook 2007 provides a categorization system with which Outlook items can be easily identified and grouped into user-defined categories. The Category object represents a user-defined category.

Use the Add method of the Categories property for the NameSpace object to create a new Category object, adding the category to the Master Category List for that namespace.

Use the Name property to specify the name of the category, the Color property to specify the color displayed for that category, and the ShortcutKey property to specify the shortcut key used to assign that category to an Outlook item in the Outlook user interface. Use the CategoryID property to retrieve the unique identifer for a category.

Assigning Categories to Items

Categories can be assigned to Outlook items by specifying the names of the appropriate Category objects in a comma-delimited string in the Categories property of the following objects:

AppointmentItem RemoteItem
ContactItem ReportItem
DistListItem SharingItem
DocumentItem TaskItem
JournalItem TaskRequestAcceptItem
MailItem TaskRequestDeclineItem
MeetingItem TaskRequestItem
NoteItem TaskRequestUpdateItem
PostItem

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.

Visual Basic for Applications
  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