Meeting Replies in Outlook 2003

November 26, 2009JPNo CommentsRate This ArticlenewLinks to this article


Productivity

    Remember my last post (Create Outlook toolbar buttons using VBA) where I promised some real use out of the toolbar button creation code? Well, we're going to see some of that here.

    But I'm also going to introduce some useful new code that is hot on the heels of the Outlook 2010 release.

    One of the new features in Outlook 2010 is the Meeting Reply. From the Outlook Team blog:

If an e-mail conversation gets to a point where a meeting would be more useful, just click Meeting Reply to set up a meeting with the people involved in the conversation. It will copy the content of the e-mail conversation into the meeting request, to help keep you within the context of what has already been discussed, and add the recipients to the invitation. All you need to do is choose the time and location.

    So you can avoid getting caught in the e-mail storm by suggesting a meeting instead. But what do you do if you are sticking with Outlook 2003 and don't have (or plan to get) Outlook 2010?

    Here's how you can duplicate the technique in Outlook 2003 with a bit of VBA code. But we'll do it one better, because we'll put in the time automatically (sort of). All you need to do is pick the location!

    Be sure to copy the entire code section below to a standard module in Outlook's VB IDE. You'll also want to visit Create Outlook toolbar buttons using VBA and grab the AddToolbarButton procedure. Below the code is the breakdown of how it works.

Enum MessageBoxButtons
  vbOKOnly = 0
  vbOKCancel = 1
  vbAbortRetryIgnore = 2
  vbYesNoCancel = 3
  vbYesNo = 4
  vbRetryCancel = 5
  vbCritical = 16
  vbQuestion = 32
  vbExclamation = 48
  vbInformation = 64
  vbDefaultButton1 = 0
  vbDefaultButton2 = 256
  vbDefaultButton3 = 512
  vbDefaultButton4 = 768
  vbApplicationModal = 0
  vbSystemModal = 4096
  vbMsgBoxHelpButton = 16384
  vbMsgBoxSetForeground = 65536
  vbMsgBoxRight = 524288
  vbMsgBoxRtlReading = 1048576
End Enum

Sub MeetingReply()
' create meeting based on email
' inspired by Outlook 2010 new feature of the same name

  On Error GoTo ErrorHandler

  Const MACRO_TITLE As String = "Meeting Reply"

  Dim olApp As Outlook.Application
  Dim olNS As Outlook.NameSpace
  Dim selectedMailItem As Outlook.MailItem
  Dim selectedRecipient As Outlook.recipient
  Dim selectedRecipients As Outlook.Recipients
  Dim mtgReply As Outlook.AppointmentItem
  Dim mtgReplyRecipients As Outlook.Recipients
  Dim startInfo As String

  Set olApp = GetOutlookApp
  Set olNS = GetNS(olApp)
  Set selectedMailItem = GetMailItem

  If selectedMailItem Is Nothing Then
    Call MessageBox("No message is selected or open. Please select or open an email to create a meeting reply.", , MACRO_TITLE)
    GoTo ProgramExit
  End If

  If MessageBox("Are you sure you want to create a Meeting Reply for this message?", vbYesNo, MACRO_TITLE) <> vbYes Then
    GoTo ProgramExit
  End If

  ' get recipients of original email
 Set selectedRecipients = selectedMailItem.Recipients

  ' create meeting from selectedMailItem message
 Set mtgReply = olApp.CreateItem(olAppointmentItem)
  Set mtgReplyRecipients = mtgReply.Recipients

  ' loop through recipients of message and add to meeting attendees
 ' do not add yourself!
 For Each selectedRecipient In selectedRecipients
    If selectedRecipient.Name <> olNS.CurrentUser Then
      mtgReplyRecipients.Add selectedRecipient.Name
    End If
  Next selectedRecipient

  ' finally, add message sender (since they're not a recipient)
 mtgReplyRecipients.Add selectedMailItem.senderName

  startInfo = InputBox("Enter the start date and time in the format: mm/dd/yyyy hh:mm", MACRO_TITLE)

  If Len(startInfo) = 0 Then ' blank entry, or Cancel clicked
   Call MessageBox("No Meeting Reply created.", , MACRO_TITLE)
    GoTo ProgramExit
  End If

  ' set selected meeting reply properties
 With mtgReply
    .Body = selectedMailItem.Body
    .Subject = selectedMailItem.Subject
    .Start = CDate(startInfo)
    .Duration = 60
    .BusyStatus = olBusy
    .MeetingStatus = olMeeting

    Call MessageBox("Enter the location of the meeting, review the details and click Send.", , MACRO_TITLE)

    .Display
  End With

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.Description
  Resume ProgramExit
End Sub

Function GetOutlookApp() As Outlook.Application
' returns reference to native Application object
 Set GetOutlookApp = Outlook.Application
End Function

Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
  Set GetNS = app.GetNamespace("MAPI")
End Function

Function GetMailItem() As Outlook.MailItem

  On Error Resume Next

  Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"

      If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
        Set GetMailItem = ActiveExplorer.Selection.Item(1)
      End If

    Case "Inspector"

      If TypeName(ActiveInspector.currentItem) = "MailItem" Then
        Set GetMailItem = ActiveInspector.currentItem
      End If
  End Select
  On Error GoTo 0
End Function

Function MessageBox(prompt As String, Optional buttons As MessageBoxButtons = 0, Optional title As Variant) As VbMsgBoxResult  ' As Integer
' rewrite of VBA's MsgBox Function
' will return one of the following seven values:
' vbOK      - 1
' vbCancel  - 2
' vbAbort   - 3
' vbRetry   - 4
' vbIgnore  - 5
' vbYes     - 6
' vbNo      - 7

Dim titleString As String

  If IsMissing(title) Then
    titleString = Application.Name
  Else
    titleString = CStr(title)
  End If

  MessageBox = MsgBox(prompt, buttons, title)
End Function

    To add this code to a toolbar button, run the following procedure once:

Sub maketoolbarbutton()

  Call AddToolbarButton("Meeting Reply", "Send Meeting Reply", "MeetingReply", , , msoButtonIconAndCaption)

End Sub

    The above procedure will call the AddToolbarButton function (which you grabbed from Create Outlook toolbar buttons using VBA) to set up the button for you.

Meeting Reply

    The Enum section at the top of the procedure is used exclusively by the MessageBox function (which you might recognize from A VBA MsgBox Replacement). We don't really need a custom messagebox function, so you can do away with this if you like, and just use MsgBox instead.

    The first thing MeetingReply does is set a reference to the default Namespace, primarily so we can check the username later in the procedure. Next we call the custom function GetMailItem to return a reference to the currently selected or opened MailItem.

    After a new meeting item is created, we add the recipients from the original email to it (minus yourself, of course; as the organizer, you're already added). You will then be prompted to enter the start date and time for the meeting. After setting a few important properties of the meeting item, it is displayed on screen for you to verify the details and click Send to request the meeting.

    But wait, there's more.

    Our meetings will always be 60 minutes by default. How can we change the macro so we can choose how long the meeting should be? I suppose we can just add another input box, but we've got two or three dialog boxes already. If we change the procedure to a function that takes a parameter, it disappears from the UI and we can't assign it to a toolbar button. In the next post, we'll discover a way around this limitation.

About JP
I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space if you want to learn more about VBA. Keep Reading »

↑ Scroll to top
Previous Post:

Next Post:

2 Response(s) to Meeting Replies in Outlook 2003 ↓

  1. Patrick Wood says:

    You always write such practical, well written, and helpful posts Jimmy. Your newsletter is always one of my favorites. Thanks again for another great post.

Speak Your Mind

Tell us what you're thinking...

Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].




Site last updated August 24, 2010 @ 5:56 pm