Set Category to outlook mails in VBA


  • hi

    i need to set the categories for the outlook mails based on the file attachment, where the categories are already predefined in outlook using VBA

    - Ram

    Friday, February 01, 2013 5:03 AM

All replies

  • That simple. Category that text field. You can add it by the rule written in VBA or assigned in another process.

    If you want to base on attachments extensions, you should to know that is one category but you can have more then one file with many different one in email.

    To look on categories you defined before you can run this code.

    Private Sub GetCategoryNames()
        Dim oStores As Outlook.Stores
        Dim oStore As Outlook.Store
        Dim oCategories As Outlook.Categories
        Dim oCategory As Outlook.Category
        Dim strOutput As String
        Set oStores = Application.Session.Stores
        For Each oStore In oStores
            Set oCategories = oStore.Categories
            If oCategories.Count > 0 Then
            For Each oCategory In oCategories
                strOutput = strOutput & "Category Name: """ & oCategory.Name & """, " _
                & oCategory.Color & ", " & oCategory.ShortcutKey & vbCrLf
            End If
            strOutput = oStore.DisplayName & vbCrLf _
            & "--------------Categories-----------------" & vbCrLf _
            & strOutput
            MsgBox strOutput
            strOutput = ""
     Set oStores = Nothing
     Set oStore = Nothing
     Set oCategories = Nothing
     Set oCategory = Nothing
    End Sub

    If you have more q. write there ;]

    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Friday, February 01, 2013 8:02 AM
  • hi

    thank you for the reply 

    i need to set the category whenever the emails reaches the inbox by predefined categories based on the  "From" Address

    - Ram

    Friday, February 08, 2013 4:43 PM
  • You can try the simple rule (script attach in rules wizard)

    Private Sub GetCategoryToIncommingMail(item as mailitem)
        Item.Categories = "some category"
    End Sub

     more about rules you can find there

    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Monday, February 11, 2013 9:32 PM