none
Developing a Sorting System for Meeting Invitations RRS feed

  • Question

  • I need the code I have to run upon the receiving of an acceptance/decline/tentative response.

    I have a macro that exists called SetAppointmentColor() and it works just fine, but it has to be called manually. I was able to get it to trigger and run when I receive a new e-mail, but I'd like to it to run only when I receive a status update on a meeting/appointment.

    Any help would be greatly appreciated, I feel I am missing something very small. 

    Private Sub Application_Startup()
        Call SetAppointmentColor
    End Sub


    Private Sub Application_NewMail()
        Call SetAppointmentColor
    End Sub

    These are the two triggers I am currently using. 

    Wednesday, December 13, 2017 6:39 PM

All replies

  • Hello,

    Please handle Items.ItemAdd Event (Outlook), check the message class of the item and run your macro.

    IPM.Schedule.Meeting.Resp.Neg Responses to decline meeting requests
    IPM.Schedule.Meeting.Resp.Pos Responses to accept meeting requests
    IPM.Schedule.Meeting.Resp.Tent Responses to tentatively accept meeting requests
    Public WithEvents myOlItems As Outlook.Items
    
    Private Sub Application_Startup()
    Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    End Sub
    
    Private Sub myOlItems_ItemAdd(ByVal item As Object)
    If item.MessageClass = "IPM.Schedule.Meeting.Resp.Pos" Then
    MsgBox ("User has accepted the meeting request")
    End If
    End Sub

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" 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.

    Thursday, December 14, 2017 3:27 AM
    Moderator
  • I removed my code and simply inserted the above code into ThisOutlookSession in hopes that it would do what i'd hoped. 

    I need VBA code that recognizes meeting acceptances/declines/tentatives as they come in. In my line of work I send out a lot of meeting invites, and very few are accepted, so I would like it to automatically update my calendar to "Green Category" everytime I receive one, I am not particularly strong in VBA, but I can typically edit code to my needs. 

    Thursday, December 14, 2017 8:06 PM
  • The issue that is arising is that I have folders that aren't the default inbox and all of those folders don't trigger the macro.

    is there a command instead of 

    Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

    that pulls all items from all folders? 

    Thursday, December 14, 2017 8:51 PM
  • this is what I have

    Public WithEvents myOlItems As Outlook.Items

    Private Sub Application_Startup()
    Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    End Sub

    Private Sub myOlItems_ItemAdd(ByVal item As Object)

    If item.MessageClass = "IPM.Schedule.Meeting.Resp.Pos" Then
    MsgBox ("User has accepted the meeting request")
    item.Categories = "Green Category"

    ElseIf item.MessageClass = "IPM.Schedule.Meeting.Resp.Neg" Then
    MsgBox ("User has declined the meeting request")
    If item.Categories = "Green Category" Then
    ElseIf item.Categories = "" Then
    item.Categories = "Red Category"
    End If
    End If
    End Sub

    It works exactly how I'd like, I just need it to read from all inboxes, not just the main inbox. Currently I have to disable my rules, I have all accepts / declines going into a folder that I can easily clear when need be. 

    Thursday, December 14, 2017 10:59 PM
  • Hello,

    You could use Application.NewMailEx Event (Outlook). The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item.

    Please notice:

    For users with an Exchange Server account (non-Cached Exchange Mode or Cached Exchange Mode), the event will fire only for messages that arrive at the server after Outlook has started. The event will not fire for messages that are synchronized in Cached Exchange Mode immediately after Outlook starts, nor for messages that are already on the server when Outlook starts in non-Cached Exchange Mode.

    Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim myItem As Object
    Set myItem = Application.GetNamespace("MAPI").GetItemFromID(EntryIDCollection)
    If myItem.MessageClass = "IPM.Schedule.Meeting.Resp.Pos" Then
    MsgBox ("User has accepted the meeting request")
    End If
    End Sub

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" 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.

    Friday, December 15, 2017 5:47 AM
    Moderator
  • This is excellent! I am sorry but I have one more question. 

        

    Public Sub Application_NewMailEx(ByVal EntryIDCollection As String)

    Dim ItemCat As String

    Dim myItem As Object
    Set myItem = Application.GetNamespace("MAPI").GetItemFromID(EntryIDCollection)
    If myItem.MessageClass = "IPM.Schedule.Meeting.Resp.Pos" Then
    MsgBox ("User has accepted the meeting request")
    MsgBox ("The Category is:" + ItemCat)
        If myItem.Categories = "Red Category" Then
        myItem.Categories = "Orange Category"
        ItemCat = myItem.Categories
        MsgBox ("The Category is:" + ItemCat)
        Else: myItem.Categories = "Green Category"
        ItemCat = myItem.Categories
        MsgBox ("The Category is:" + ItemCat)
        End If

    ElseIf myItem.MessageClass = "IPM.Schedule.Meeting.Resp.Neg" Then
    MsgBox ("User has declined the meeting request")
    ItemCat = myItem.Categories
    MsgBox ("The Category is:" + ItemCat)
        If ItemCat = "Green Category" Then
        myItem.Categories = "Orange Category"
        ItemCat = myItem.Categories
        MsgBox ("The Category is:" + ItemCat)
        Else: myItem.Categories = "Red Category"
        ItemCat = myItem.Categories
        MsgBox ("The Category is:" + ItemCat)
        End If
    End If
    End Sub

    The problem is I never get into the "Orange Category" part of the code. The problem is the ItemCat is always blank at the start of every if statement, even if the category it is in is already green. 


    Friday, December 15, 2017 6:57 PM
  • Hello,

    For a new received mail item, the category should be blank. I do not think we could receive a mail with a category attached. As your original issue has been resolved, i suggest you close this thread and post a new thread. In the new thread, i suggest you share when you add the green category to the new mail item.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" 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.

    Monday, December 18, 2017 7:26 AM
    Moderator
  • Thanks for the information and i still suggest OP post a new thread for the issue about category of incoming mail as original issue is about running macro when receiving a new item.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" 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, December 19, 2017 6:24 AM
    Moderator