Articles under Outlook 2003 Object Model breakdown — The AppointmentItem Object:

AppointmentItem

The AppointmentItem object represents Calendar appointments and meetings in Outlook. This article series will show you various ways to automate them.

Create Appointments in default local Calendar

Simple appointments may be created in the local Calendar. This function will create the appointment and return it to the calling procedure for further manipulation.

Function CreateAppointment() As Outlook.AppointmentItem
  Set CreateAppointment = Outlook.CreateItem(olAppointmentItem)
End Function

Create Appointments in non-default local folder that holds Calendar items

Appointments may also be created in any folder that can hold calendar items. This function uses the Folder.Add method and takes a MAPIFolder object as its argument. The newly added appointment is returned to the calling procedure.

Function CreateAppointmentAltFolder(fldr As Outlook.MAPIFolder) _
    As Outlook.AppointmentItem
  If fldr.DefaultItemType = olAppointmentItem Then
    Set CreateAppointmentAltFolder = fldr.Items.Add(olAppointmentItem)
  End If
End Function

Create Appointments in shared default Calendar folders

If a co-worker has a shared calendar folder, anyone with access can add items (i.e. appointments, meetings) to that folder.

This function creates an appointment in the specified user's shared Calendar folder and returns that item to the calling procedure. You pass in either a resolved Recipient object or the name of a user whose shared Calendar folder you have access to and want to create an Appointment for.

Function CreateSharedDefaultAppointment(recip As Variant) As Outlook.AppointmentItem

Dim olNS As Outlook.NameSpace
Dim fldr As Outlook.MAPIFolder
Dim tempRecip As Outlook.Recipient

  Select Case TypeName(recip)
    Case "Recipient"
      ' Recipient object already created
      Set fldr = olNS.GetSharedDefaultFolder(recip, olFolderCalendar)

    Case "String"
      ' create Recipient object
      Set olNS = GetNS(GetOutlookApp)
      Set tempRecip = olNS.CreateRecipient(recip)

      Set fldr = olNS.GetSharedDefaultFolder(tempRecip, olFolderCalendar)

  End Select

  Set CreateSharedDefaultAppointment = fldr.Items.Add(olAppointmentItem)

End Function
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
  Set GetNS = app.GetNamespace("MAPI")
End Function
Function GetOutlookApp() As Outlook.Application
' returns reference to native Application object
  Set GetOutlookApp = Outlook.Application
End Function

If a Recipient object is passed to the function, the new AppointmentItem is created directly. If only a name is passed, a temporary Recipient object is created using the Outlook.NameSpace.CreateRecipient Method.

Site last updated: February 12, 2012