Automatic “In Meeting” Response


 

Imagine this scenario. You’ve sent an email to someone and are waiting for their response. It’s been awhile, an hour or two, since you sent the message, and they haven’t replied. You start to wonder if they got the message, if they are too busy to respond, or if they are just ignoring you. Finally, you pick up your phone and call them. The person answers and tells you they’ve been in a meeting and just got back to their office. Or maybe that situation is reversed and you were the one in the meeting while a co-worker or client was waiting for you to respond. Sound familiar? Wouldn’t it be great if Outlook could respond for you, telling the sender that you’re in a meeting and that you will read and reply to their message as soon as you can?

That’s exactly what the script in this post does. It watches your inbox for new messages and takes action when one arrives. First, it checks to see if the new item is an email. If it’s not, then the script ignores it. Next, the script checks your calendar to see if you’re busy. Busy, in this context, is any appointment or meeting occurring at the time the message arrived, where you’ve either checked the “All day event” box or set the appointment’s “Show As” status to anything other than “Free”. Finally, if the script determines that you are in a meeting/have an appointment, then it sends a reply to the sender telling them that. Here are a few examples. It’s 10:00 AM and a customer’s email just arrived in your inbox.

  • Your calendar shows an appointment that runs from 9:30 AM – 10:30 AM with the “Show As” status set to “Busy”. The script sends a reply to the customer telling them that you’re in a meeting.
  • Your calendar shows no appointments at 10:00 AM. The script takes no action.
  • Your calendar shows a meeting that runs from 9:30 AM – 10:30 AM, but the “Show As” status is set to “Free”. The script takes no action.

I created this script for myself because I wanted to provide better service to my customers, both internal and external. While an internal customer could check my calendar to see if I’m in a meeting, I felt that proactively notifying them was better. It saves them time and doesn’t require any action of their part. An external customer can’t see my calendar, so for them it’s an even bigger plus, especially on those days when I have a lot of meetings. Of course I could have accomplished the same thing by activating “Out of Office” each time I leave for a meeting. But, I’d have to remember to turn it on, and off again when I returned, for each appointment. That’s too much work, and too easy for me to forget. It’s a lot easier to let the script handle the work for me. And for those of you who don’t have your mailbox on an Exchange server, Out of Office isn’t even an option.

Requirements.

This solution should work in Outlook 2003 and later. Outlook must be open and running for scripts to work.

Instructions and Code.

The code comes in two parts.

Part 1

Follow these instructions to add part 1 of the code.

  1. Start Outlook
  2. Press ALT+F11 to open the VB editor
  3. If not already expanded, expand Microsoft Office Outlook Objects
  4. Right-click on Class Modules, select Insert > Class Module
  5. In the Properties panel click on Name and enter clsInMeeting
  6. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  7. Edit the code as needed. I included a comment where changes are needed or allowed.
  8. Click the diskette icon on the toolbar to save the changes
'On the next line edit the response the code will send when you receive an email while in a meeting.
Const STANDARD_MSG = "I'm in a meeting right now.  I'll read and respond to your message as soon as I can."

Private WithEvents olkApp As Outlook.Application

Private Sub Class_Initialize()
    Set olkApp = Application
End Sub

Private Sub Class_Terminate()
    Set olkApp = Nothing
End Sub

Private Sub olkApp_NewMailEx(ByVal EntryIDCollection As String)
    Dim arrEID As Variant, varEID As Variant, olkItm As Object
    If InMeeting() Then
        arrEID = Split(EntryIDCollection, ",")
        For Each varEID In arrEID
            Set olkItm = olkApp.Session.GetItemFromID(varEID)
            If olkItm.Class = olMail Then
                SendReply olkItm
            End If
        Next
    End If
End Sub

Private Function InMeeting() As Boolean
    Dim olkCol As Outlook.Items, olkRes As Outlook.Items, olkApt As Outlook.AppointmentItem
    Set olkCol = Session.GetDefaultFolder(olFolderCalendar).Items
    olkCol.Sort "[Start]"
    olkCol.IncludeRecurrences = True
    Set olkRes = olkCol.Restrict("[Start] <= '" & Format(Now, "ddddd h:nn AMPM") & "' AND [End] >= '" & Format(Now, "ddddd h:nn AMPM") & "'")
    For Each olkApt In olkRes
        If (olkApt.AllDayEvent) Or (olkApt.BusyStatus = olFree) Then
            InMeeting = False
        Else
            InMeeting = True
            Exit For
        End If
    Next
End Function

Private Sub SendReply(olkMsg As Outlook.MailItem)
    Dim olkRpl As Outlook.MailItem
    Set olkRpl = olkMsg.Reply
    With olkRpl
        .Body = STANDARD_MSG
        .Send
    End With
    Set olkRpl = Nothing
End Sub

Part 2.

Follow these instructions to add part 2 of the code.

Outlook 2007.

  1. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  2. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  3. Click the diskette icon on the toolbar to save the changes
  4. Close the VB Editor
  5. Click Tools > Trust Center
  6. Click Macro Security
  7. Set Macro Security to “Warnings for all macros”
  8. Click OK
  9. Close Outlook
  10. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.

Outlook 2010.

  1. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  2. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  3. Click the diskette icon on the toolbar to save the changes
  4. Close the VB Editor
  5. Click File and select Options
  6. When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
  7. Click Macro Settings
  8. Select either of the two bottom settings (i.e. “Notifications for all macros” or “Enable all macros (not recommended; potentially dangerous code can run)”. The choice of which to chose is up to you. If you select “Notifications”, then you’ll be prompted at times to enable macros. If you pick “Enable all” then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume.
  9. Click Ok until the dialog-boxes have all closed
  10. Close Outlook
  11. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Dim objCIM As clsInMeeting

Private Sub Application_Quit()
    Set objCIM = Nothing
End Sub

Private Sub Application_Startup()
    Set objCIM = New clsInMeeting
End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s