如何:创建约会

此示例创建一个约会并将收件人添加到约会会议请求中。

**适用于:**本主题中的信息适用于 Outlook 2007 和 Outlook 2010 的应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能

示例

Private Sub AddAppointment()
    Dim newAppointment As Outlook.AppointmentItem = Me.Application.CreateItem _
         (Outlook.OlItemType.olAppointmentItem)
    Try
        With newAppointment
            .Start = Date.Now.AddHours(2)
            .End = Date.Now.AddHours(3)
            .Location = "ConferenceRoom #2345"
            .Body = _
                "We will discuss progress on the group project."
            .Subject = "Group Project"
            .AllDayEvent = False
            .Recipients.Add("Roger Harui")
            Dim sentTo As Outlook.Recipients = .Recipients
            Dim sentInvite As Outlook.Recipient
            sentInvite = sentTo.Add("Holly Holt")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olRequired
            sentInvite = sentTo.Add("David Junca")
            sentInvite.Type = Outlook.OlMeetingRecipientType.olOptional
            sentTo.ResolveAll()
            .Save()
            .Display(True)
        End With
    Catch ex As Exception
        MsgBox("The following error occurred: " & _
            ex.Message)
    End Try
End Sub
private void AddAppointment()
{
    try
    {
        Outlook.AppointmentItem newAppointment =
            (Outlook.AppointmentItem)
        this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
        newAppointment.Start = DateTime.Now.AddHours(2);
        newAppointment.End = DateTime.Now.AddHours(3);
        newAppointment.Location = "ConferenceRoom #2345";
        newAppointment.Body =
            "We will discuss progress on the group project.";
        newAppointment.AllDayEvent = false;
        newAppointment.Subject = "Group Project";
        newAppointment.Recipients.Add("Roger Harui");
        Outlook.Recipients sentTo = newAppointment.Recipients;
        Outlook.Recipient sentInvite = null;
        sentInvite = sentTo.Add("Holly Holt");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            .olRequired;
        sentInvite = sentTo.Add("David Junca ");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            .olOptional;
        sentTo.ResolveAll();
        newAppointment.Save();
        newAppointment.Display(true);
    }
    catch (Exception ex)
    {
        MessageBox.Show("The following error occurred: " + ex.Message);
    }
}

请参见

任务

如何:创建自定义日历

如何:向 Outlook 联系人添加项

概念

使用日历项