Autoaccept a Meeting Request using Rules

Last reviewed on April 4, 2014

An interesting problem came up in the Microsoft public newsgroups this week. Richard posts:

We have a specific user requirement to auto accept meeting requests only from some selected organizers, but I don't see any choice in Rule Wizard for meeting requests. Does anyone have an idea, please?

Create a ruleOf course I have an idea. Begin with a rule using the conditions "from people or distribution list" and "uses the specified form", choosing the Meeting Request form under Application forms.

Since there is not an action to respond to meeting requests, you'll need to use a script to accept it. Outlook MVP Michal Bednarz offers this script, which you need to add to ThisOutlookSession before creating the rule.

This was tested in Outlook 2007 and should work in any version which supports the Run a Script action.

The Code

Sub AutoAcceptMeetings(oRequest As MeetingItem)

If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then
  Exit Sub
End If

Dim oAppt As AppointmentItem
Set oAppt = oRequest.GetAssociatedAppointment(True)

Dim oResponse
 Set oResponse = oAppt.Respond(olMeetingAccepted, True)
 oResponse.Display
End Sub

How to use

Open Outlook's VBA editor (Alt+F11), expand Microsoft Office Outlook Objects then double click on ThisOutlookSession. Type or paste the code into the module, then create the rule with the 'run script' Action and select this script

To decline a meeting, replace olMeetingAccepted with olMeetingDeclined:

Set oResponse = oAppt.Respond(olMeetingDeclined, True)

To Save with no response sent

To accept the meeting and add it to your calendar automatically, without sending a response, Christopher changed the last part of the code to:

Dim oResponse

Set oResponse = oAppt.Respond(olMeetingAccepted, True)
oResponse.Close (olSave)

End Sub

To Delete from the Inbox once processed

Add the following before End Sub:

oRequest.Delete

Apply rule to meetings scheduled for a specific day of the week

This edit uses the WeekDayName function to get the day of the week and automatically process the meeting. Use the full weekday name in the string.

dayWed = WeekdayName(Weekday(oAppt.Start))
If dayWed = "Wednesday" Then

Sub AutoAcceptMeetingsWed(oRequest As MeetingItem)

If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then
  Exit Sub
End If
     
Dim oAppt As AppointmentItem
Set oAppt = oRequest.GetAssociatedAppointment(True)

dayWed = WeekdayName(Weekday(oAppt.Start))
   
If dayWed = "Wednesday" Then

Dim oResponse
 Set oResponse = oAppt.Respond(olMeetingAccepted, True)
 oResponse.Send

End If
End Sub

Check Free/Busy before accepting

Steve wanted to know how to decline if there was a conflict. For this we need to check Free/Busy. Checking the Free/Busy is actually fairly easy and the code we need is at Recipient.FreeBusy Method.

Set yourself as a Recipient, using your email address, display name, or alias:

Set myAcct = Session.CreateRecipient("alias@slipstick.com")

Then get your Free/Busy string:

myFB = myAcct.FreeBusy(oAppt.Start, 5, False)

You need a date to check, and we'll use the appointment start date. The Free/Busy string begins at midnight on this date.

The next value is how many minutes are in each Free/Busy "period" represented by the myFB string. After much trial and error, I've decided that 5 minutes is probably the best value, since it's the smallest time period displayed on the calendar.

The final value is True or False (if you leave it blank, it's False). False tells Outlook to either return 0 for Free (and Working elsewhere in Outlook 2013) and 1 for "not free". True returns values specific to the Show time as setting.

Next, you need to know how many time periods are between midnight and the appointment time (there are 288 5 minutes periods each day):

i = (TimeValue(oAppt.Start) * 288)

Use that value to create a string of the periods the appointment covers. If you want to build in some downtime between appointments, subtract from i before calculating ( i - 2 gives 10 min between appointments) and add the same value to the duration calculation.

test = Mid(myFB, i, oAppt.Duration / 5)

test = Mid(myFB, i-2, (oAppt.Duration / 5)+2) starts 2 periods before the start time, or in my example, leaves 10 min between the last appointment and this one.

Finally, we use InStr to look for a match within the substring that covers our appointment period. If the string contains a 1, the appointment should be declined:

If InStr(1, test, "1") Then

To help you understand the code (and check my calculations), I left my Debug.Print code in. Open the Immediate windows in the VB Editor using Ctrl+G or select it from the View menu to see the results. Those 0, 1, and 2's each represent a 5 minute block of time beginning at 12:00 AM on that date.

Debug.print results in the Immediate window

 
If oRequest.MessageClass <> "IPM.Schedule.Meeting.Request" Then
  Exit Sub
End If
 
Dim oAppt As AppointmentItem
Set oAppt = oRequest.GetAssociatedAppointment(True)

Dim myAcct As Outlook.Recipient
Dim myFB As String

Set myAcct = Session.CreateRecipient("alias@slipstick.com")

Debug.Print oAppt.Duration
Debug.Print "Time: " & TimeValue(oAppt.Start)
Debug.Print "periods before appt: " & TimeValue(oAppt.Start) * 288
Debug.Print oAppt.Start

myFB = myAcct.FreeBusy(oAppt.Start, 5, False)

Debug.Print myFB

Dim oResponse
Dim i As Long
Dim test As String

i = (TimeValue(oAppt.Start) * 288)
test = Mid(myFB, i - 2, (oAppt.Duration / 5) + 2)

Debug.Print "String to check: " & test

If InStr(1, test, "1") Then
 Set oResponse = oAppt.Respond(olMeetingDeclined, True)
 oResponse.Display
 
 Else
  Set oResponse = oAppt.Respond(olMeetingAccepted, True)
 oResponse.Display
End If
End Sub

If you want to check for specific values or consider tentative appointments as Free, you can change If InStr(1, test, "1") Then to use different values. Use If InStr(1, test, "2") or InStr(1, test, "3") Then to check for Busy and Out of Office.

Free/BusyValue
Free0
Tentative1
Busy2
Out of Office3
Working Elsewhere (Outlook 2013)0

Macro Security

Macro security needs to be set on Notify for all macros. Using Enable All macros is a poor choice as it is often reset to the signed macros only option by security software or updates. If you prefer, you can sign the macro using SelfCert and set security to Signed macros only. If you choose to use SelfCert, sign the macro after you are finished editing it as it will need to be re-signed after each edit.

To access macro security dialog, go to File, Options, Trust Center in Outlook 2010. Use Tools, Macros, Security menu in Outlook 2007 and older. When security is set to Notify, you will be asked if you want to run the macro each time you start Outlook.

Complete steps for using the VBA Editor and SelfCert are at How to use the VBA Editor

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

If the Post Coment button disappears, press your Tab key.