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?
Of 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.
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
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
Turn off Reminders
To turn reminders off on the meeting, add these lines to the code. It can either go right after the 'Set oAppt' line or before End Sub.
Appt.ReminderSet = False
To Delete from the Inbox once processed
Add the following before End Sub:
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
Set yourself as a Recipient, using your email address, display name, or alias:
Set myAcct = Session.CreateRecipient("firstname.lastname@example.org")
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.
Sub CheckFreeBusy(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 myAcct As Outlook.Recipient Dim myFB As String Set myAcct = Session.CreateRecipient("email@example.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.
|Out of Office||3|
|Working Elsewhere (Outlook 2013)||0|
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
More Run a Script Samples:
- Automatically Add a Category to Accepted Meetings
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Delegates, Meeting Requests, and Rules
- Delete attachments from messages
- Forward meeting details to another address
- How to Change the Font used for Outlook's RSS Feeds
- Keep Canceled Meetings on Outlook's Calendar
- Macro to Print Outlook email attachments as they arrive
- Move messages CC'd to an address
- Outlook AutoReplies: One script, many responses
- Outlook's Rules and Alerts: Run a Script
- Process messages received on a day of the week
- Read Outlook Messages using Plain Text
- Receive a Reminder When a Message Doesn't Arrive?
- Run a script rule: Autoreply using a template
- Run a Script Rule: Change Subject then Forward Message
- Run a script rule: Reply to a message
- Run a Script Rule: Send a new message when a message arrives
- Run Rules Now using a Macro
- Save all incoming messages to the hard drive
- Save and Rename Outlook Email Attachments
- Save Outlook email as a PDF
- Sort messages by Sender domain
- Use a macro to copy data in Outlook email to Excel workbook
- Use a Rule to delete older messages as new ones arrive
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments