共用方式為


建立具有每周模式的週期性約會

此範例示範如何建立具有每周模式的週期性約會 (例如,每個星期一、星期三和星期五的約會) 。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

當您建立新的週期性約會時,週期性模式是以您在建立約會時指定的時間為基礎。 例如,如果您建立每天下午 1:00 重複的約會,則約會只會在每天下午 1:00 重複。 若要變更約會的週期模式,請設定約會 RecurrencePattern 物件的屬性。 設定 RecurrencePattern 物件的 RecurrenceType 屬性,再設定其他 RecurrencePattern 屬性。 下表顯示 OlRecurrenceType 列舉) 所指定之指定 RecurrenceType (的有效 RecurrencePattern 屬性。

OlRecurrenceType 值

有效的 RecurrencePattern 屬性

olRecursDaily

DurationEndTimeIntervalNoEndDateOccurrencesPatternStartDatePatternEndDateStartTime

olRecursWeekly

DayOfWeekMask, Duration, EndTime, Interval, NoEndDate, Occurrences, PatternStartDate, PatternEndDate, StartTime

olRecursMonthly

DayOfMonth, Duration, EndTime, Interval, NoEndDate, Occurrences, PatternStartDate, PatternEndDate, StartTime

olRecursMonthNth

DayOfWeekMask, Duration, EndTime, Interval, Instance, NoEndDate, Occurrences, PatternStartDate, PatternEndDate, StartTime

olRecursYearly

DayOfMonth、Duration、EndTime、Interval、 MonthOfYear、NoEndDate、Occurrences、PatternStartDate、PatternEndDate、StartTime

olRecursYearNth

DayOfWeekMask、Duration、EndTime、Interval、Instance、NoEndDate、Occurrences、PatternStartDate、PatternEndDate、StartTime

當您使用週期性約會專案時,您應該釋放任何先前的參考、在存取或修改專案之前取得週期性約會專案的新參考,並在完成並儲存變更後立即釋放這些參考。 此作法適用於週期性 AppointmentItem 物件,以及任何 ExceptionRecurrencePattern 物件。 若要在 Visual Basic 中釋放參考,請將該現有物件設定為 Nothing。 在 C# 中,明確釋放該物件的記憶體。

請注意,即使在您釋放您的參考並嘗試取得新的參考之後,如果另一個載入宏或 Outlook) 另一個載入宏 (保留使用中參考,您的新參照仍會指向物件的過期複本。 因此,請務必在完成週期性約會後立即釋出您的參考。

在下列程式代碼範例中,RecurringAppointmentEveryMondayWednesdayFriday 會建立 AppointmentItem 物件,然後呼叫 GetRecurrencePattern () 來取得新建立約會的 RecurrencePattern 物件。 RecurringAppointmentEveryMondayWednesdayFriday 然後設定 RecurrenceType、 DayOfWeekMask、PatternStartDate、PatternEndDate、Duration、StartTime、EndTime 和 Subject 屬性、儲存約會,最後顯示約會,其模式為「發生在 2006 年 7 月 10 日的每星期一、星期三和星期五,直到 2006/8/25 下午 2:00 到下午 3:00」。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void RecurringAppointmentEveryMondayWednesdayFriday()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.Subject = "Recurring Appointment DaysOfWeekMask Example";
    Outlook.RecurrencePattern pattern = appt.GetRecurrencePattern();
    pattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly;
    // Logical OR for DayOfWeekMask creates pattern
    pattern.DayOfWeekMask = Outlook.OlDaysOfWeek.olMonday |
        Outlook.OlDaysOfWeek.olWednesday |
        Outlook.OlDaysOfWeek.olFriday;
    pattern.PatternStartDate = DateTime.Parse("7/10/2006");
    pattern.PatternEndDate = DateTime.Parse("8/25/2006");
    pattern.Duration = 60;
    pattern.StartTime = DateTime.Parse("2:00:00 PM");
    pattern.EndTime = DateTime.Parse("3:00:00 PM");
    appt.Save();
    appt.Display(false);
}

另請參閱