共用方式為


使用預設週期模式建立週期性約會

此範例示範如何使用預設週期模式建立週期性約會。

範例

注意事項

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

當您在 Outlook 中建立約會時,您會建立 AppointmentItem 物件。 如果 AppointmentItem 的 IsRecurring 屬性設定為 true,您的約會就會是週期性約會。 無法直接設定IsRecurring。

不過,您可以使用 RecurrencePattern 物件來建立週期性約會。 若要以程式設計方式建立週期性約會,請建立 AppointmentItem 對象、呼叫 GetRecurrencePattern () AppointmentItem 物件的方法,然後儲存 AppointmentItem 物件。 這會建立使用默認週期模式的約會,該模式每周會在約會建立的星期幾發生,而且沒有結束日期。 RecurrencePattern 物件可讓您以指定的間隔建立週期性約會:每日、每周、每月或每年。 如果您未指定 RecurrencePattern 物件的間隔,Outlook 將會使用預設的週期模式。

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

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

在下列範例中,CreateRecurringAppointment 會建立 AppointmentItem 物件。 然後呼叫 GetRecurrencePattern。 GetRecurrencePattern 會傳回 RecurrencePattern 物件,並儲存 AppointmentItem。 這會建立使用默認週期模式的週期性約會。

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 CreateRecurringAppointment()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.Subject = "Weekly Extensibility Team Meeting";
    Outlook.RecurrencePattern pattern = appt.GetRecurrencePattern();
    appt.Save();
}

另請參閱