none
VBA Macro for Outlook 2013 to decline meetings automatically between dates (newby question) RRS feed

  • Question

  • I'm trying to check incoming messages for meeting invitations that fall within a window where I will be out of the office.  As opposed to out of office manager which will only send a response after I leave, this is to prevent having to decline a bunch of meetings when I am still in the office, but will be gone when that meting occurs. 

    I tried the following, but get an error when I configure the rule and try to run that says it cannot find the script "" or it is invalid.  Did I do something wrong?

    The name of the macro appears when I configure the rule, which makes the error even stranger to me.

    Sub AutoProcessMeetingRequest(oRequest As MeetingItem)
        ' quit if this isn't a meeting request
        If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then Exit Sub

        Dim oAppt As AppointmentItem
        Set oAppt = oRequest.GetAssociatedAppointment(True)
        
        Dim VacStartTime, VacEndTime, ReturnDate As Date
        
        ' Set vacation dates
        VacStartTime = #8/3/2012 4:00:00 PM# ' date and time you leave the office
        VacEndTime = #8/22/2012 5:30:00 PM# ' date and time you are the latest out of the office
        
        ReturnDate = DateAdd("d", 1, VacEndTime)
        ReturnString = Format(ReturnDate, "mmmm d")
        
        If 1 = 1 Then
            Set oResponse = oAppt.Respond(olMeetingDeclined, True)
            oResponse.Body = _
                "Hello," & vbCrLf _
                & "Thank you for your message.  I will be out of the office on personal travel until " _
                & ReturnString _
                & " and will be unable to participate in your requested meeting."
            oResponse.Send
        End If
    End Sub


    • Edited by madtown77 Thursday, July 27, 2017 3:35 PM
    Thursday, July 27, 2017 2:34 PM

Answers

  • Hi madtown77,

    When will you get the error? When you configure the rule or when you receive a meeting request? How did you configure the rule? Have you renamed the macro? I suggest you re-selected the macro again to update the reference, just like


    Besides,  what's your office build number? Whats you macro security level? Could you run a simply macro in Outlook VBA?

    Best Regards,

    Terry

    • Marked as answer by madtown77 Tuesday, August 1, 2017 2:22 PM
    Friday, July 28, 2017 6:56 AM

All replies

  • Hi madtown77,

    When will you get the error? When you configure the rule or when you receive a meeting request? How did you configure the rule? Have you renamed the macro? I suggest you re-selected the macro again to update the reference, just like


    Besides,  what's your office build number? Whats you macro security level? Could you run a simply macro in Outlook VBA?

    Best Regards,

    Terry

    • Marked as answer by madtown77 Tuesday, August 1, 2017 2:22 PM
    Friday, July 28, 2017 6:56 AM
  • Seems that renaming the sub and recreating the rule solved that. 

    Below is the final working code I created:

    Sub VacationMeeting(oRequest As MeetingItem)
        ' quit if this isn't a meeting request
        If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then Exit Sub

        Dim oAppt As AppointmentItem
        Set oAppt = oRequest.GetAssociatedAppointment(True)
        
        Dim VacStartTime, VacEndTime, ReturnDate, MeetingStart As Date
        
        ' Set vacation dates
        VacStartTime = #8/3/2017 4:00:00 PM# ' date and time you leave the office
        VacEndTime = #8/22/2017 5:30:00 PM# ' date and time you are the latest out of the office
        
        ReturnDate = DateAdd("d", 1, VacEndTime)
        ReturnString = Format(ReturnDate, "mmmm d")

        MeetingStart = Format(oAppt.Start, "mm/dd/yyyy hh:mm AMPM")
        
        EndDiff = DateTime.DateDiff("h", VacEndTime, MeetingStart)
        StartDiff = DateTime.DateDiff("h", VacStartTime, MeetingStart)
        
        If (StartDiff >= 0) Then
            If (EndDiff <= 0) Then
                Dim oResponse As MeetingItem
                Set oResponse = oAppt.Respond(olMeetingDeclined, True)
                oResponse.Body = _
                    "Hello," & vbCrLf _
                    & "Thank you for your message.  I will be out of the office on personal travel until " _
                    & ReturnString _
                    & " and will be unable to participate in your requested meeting."
                oResponse.Send
                oRequest.Delete
            End If
        End If
    End Sub

    Monday, July 31, 2017 3:16 PM
  • Hi madtown77,

    I'm glad to hear that you have solved the issue. I suggest you mark your solution as answer to close this thread. Thanks for understanding.

    Best Regards,

    Terry

    Tuesday, August 1, 2017 12:59 AM