none
Categorizing Email as Triggering Event RRS feed

  • Question

  • Hi VBA experts,

    My question is about the possibility to launch a macro whenever an email is categorized.

    I've seen that there's the possibility to launch macro after specific events like sending an email or opening an email etc... but I still don't know if it possible to use the categorizing action as an event to launch a macro.

    if possible, could you please provide me with an example in which whenever an email is categorized a Msgbox ("hello") appears?

    Thanks for your help.

    Best regards

    Monday, October 30, 2017 5:14 PM

All replies

  • Hi Kyrpo,

    ->but I still don't know if it possible to use the categorizing action as an event to launch a macro.

    There is no such event but the Items.ItemChange will fire when any property of the mail is changed, which includes changing Categories.

    -> could you please provide me with an example in which whenever an email is categorized a Msgbox ("hello") appears?

    You could use a global variable to store the previous Categories using Explorer.SelectionChange Event and then compare current Categories in Items.ItemChange Event.

    Here is the example.

    Dim WithEvents itms As Items
    
    Dim WithEvents exp As Explorer
    
    Dim oCategories As String
    
    Private Sub Application_Startup()
    
    'initialize the itms and exp first
    
    Set itms = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    
    Set exp = Application.ActiveExplorer
    
    End Sub
    
    Private Sub exp_SelectionChange()
    
    Dim S As Selection
    
    Set S = Application.ActiveExplorer.Selection
    
    If S.Count = 1 Then
    
    oCategories = S.Item(1).Categories
    
    End If
    
    End Sub
    
    Private Sub itms_ItemChange(ByVal Item As Object)
    
    cCategories = Item.Categories
    
    If cCategories <> oCategories Then
    
    oCategories = cCategories
    
    MsgBox "Hello"
    
    End If
    
    End Sub

    Best Regards,

    Terry


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 31, 2017 3:13 AM