Confirm an Appointment by Email

Right click an appointment in your calendar, and send a confirmation to its linked contacts.

Last modified: 2010/08/24 | Accessed: 15.661  | #83
◀ Previous sample Next sample ▶
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.

This example demonstrates

  1. how to create your own context menu button in Outlook 2007 or higher, and
  2. how to access a contact item that is linked to an appointment.

The context menu is being displayed when you right-click an appointment item in the calendar. The example creates an email with the subject of the appointment and confirms the date. If you have entered a contact at the bottom of the appointment form, the email is automatically addressed to this contact.

Please see the source code, there're two places commented with Edit where you can adjust the caption of the button as well as the subject and the body of the email.

tip  How to add macros to Outlook
Private WithEvents ConfirmAppointment As Office.CommandBarButton

Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, _
  ByVal Selection As Selection)
  Dim obj As Object
  Dim Item As Outlook.AppointmentItem
  Dim Btn As Office.CommandBarButton
  Dim Caption$

    ' Edit
  Caption = "Confirm Appointment"

  If Selection.Count = 1 Then
    Set obj = Selection(1)
    If TypeOf obj Is Outlook.AppointmentItem Then
      Set Item = obj
      Set Btn = CommandBar.Controls.Add(msoControlButton, , , , True)
      Btn.Style = msoButtonCaption
      Btn.Caption = Caption
      Btn.Parameter = Item.EntryID
      Set ConfirmAppointment = Btn
    End If
  End If
End Sub

Private Sub ConfirmAppointment_Click(ByVal Ctrl As Office.CommandBarButton, _
  CancelDefault As Boolean)
  Dim Appt As Outlook.AppointmentItem
  Dim Mail As Outlook.MailItem
  Dim Link As Outlook.Link
  Dim Contact As Outlook.ContactItem
  Dim Message$, StartTime$, Recipient$, Subject$
  Dim EntryID$

  EntryID = Ctrl.Parameter
  If Len(EntryID) Then
    Set Appt = Application.Session.GetItemFromID(EntryID)
  End If

  If Not Appt Is Nothing Then
    Set Mail = Application.CreateItem(olMailItem)

    If Appt.Links.Count Then
      Set Link = Appt.Links(1)
      If Not Link.Item Is Nothing Then
        Set Contact = Link.Item
        If Not Contact Is Nothing Then
          Recipient = Contact.Email1Address
        End If
      End If
    End If

    ' Edit
    Subject = "Confirmation: " & Appt.Subject
    Message = "Herewith I confirm the following appointment: "

    StartTime = Format(Appt.Start, "dddd, dd. mmm yyyy hh:nn", vbUseSystemDayOfWeek, vbFirstFourDays)
    Message = Message & vbCrLf & StartTime

    Mail.To = Recipient
    Mail.Subject = Subject
    Mail.Body = Message & Mail.Body
  End If

  Set ConfirmAppointment = Nothing
End Sub
Determine the "identity" of your emails. Set with SAM the sender, signature and folder for sent items with the help of rules.
email  Send a message