在指定日期傳回 AppointmentItem 物件的特定執行個體。
語法
expression。
GetOccurrence( _StartDate_ )
運算式 代表 RecurrencePattern 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| StartDate | 必要 | Date | 代表本地時間的 Date 值。 |
傳回值
代表指定日期之特定約會的 AppointmentItem 物件。
註解
如果在指定的日期沒有該系列的約會存在,GetOccurrence 方法就會產生一個錯誤。
當您使用週期性約會項目時,應釋出任何先前的參照,在存取或修改項目之前取得週期性約會項目的新參照,並在完成並儲存變更後立即釋出這些參照。 此作法適用於週期性 AppointmentItem 物件,以及任何 Exception 或 RecurrencePattern 物件。 若要在 VBA) 或 Visual Basic (Visual Basic for Applications 中釋放參照,請將該現有物件設定 為 Nothing。 在 C# 中明確釋放該物件的記憶體。 如需程式碼範例,請參閱 AppointmentItem 物件的主題。
請注意,即使在您釋放參照並嘗試取得新的參照之後,如果其他增益集或 Outlook 對上述其中一個物件仍有作用中的參照,您的新參照仍會指向該物件的過期複本。 因此,在完成定期預約後立即發布推薦信非常重要。
範例
此 Visual Basic for Applications (VBA) 範例使用 CreateItem 建立 AppointmentItem 物件。 RecurrencePattern 是使用 GetRecurrencePattern 方法取得這個項目的。 在設定 RecurrencePattern 屬性、RecurrenceType、PatternStartDate 及 PatternEndDate 後,這些約會現在成為一系列每日發生且為期一年的週期性約會。
當使用 GetOccurrence 方法取得此週期性約會的一個執行個體,並變更此執行個體的屬性時,會建立例外狀況物件。 這一系列約會的例外狀況是使用 GetRecurrencePattern 方法取得,以存取與此系列相關聯的 例外狀況 集合。 訊息方塊會顯示此例外狀況對一系列約會的原始 主旨 和 原始日期 ,以及此例外狀況目前的日期、時間和主旨。
Public Sub cmdExample()
Dim myApptItem As Outlook.AppointmentItem
Dim myRecurrPatt As Outlook.RecurrencePattern
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myDate As Date
Dim myOddApptItem As Outlook.AppointmentItem
Dim saveSubject As String
Dim newDate As Date
Dim myException As Outlook.Exception
Set myApptItem = Application.CreateItem(olAppointmentItem)
myApptItem.Start = #2/2/2003 3:00:00 PM#
myApptItem.End = #2/2/2003 4:00:00 PM#
myApptItem.Subject = "Meet with Boss"
'Get the recurrence pattern for this appointment
'and set it so that this is a daily appointment
'that begins on 2/2/03 and ends on 2/2/04
'and save it.
Set myRecurrPatt = myApptItem.GetRecurrencePattern
myRecurrPatt.RecurrenceType = olRecursDaily
myRecurrPatt.PatternStartDate = #2/2/2003#
myRecurrPatt.PatternEndDate = #2/2/2004#
myApptItem.Save
'Access the items in the Calendar folder to locate
'the master AppointmentItem for the new series.
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderCalendar)
Set myItems = myFolder.Items
Set myApptItem = myItems("Meet with Boss")
'Get the recurrence pattern for this appointment
'and obtain the occurrence for 3/12/03.
myDate = #3/12/2003 3:00:00 PM#
Set myRecurrPatt = myApptItem.GetRecurrencePattern
Set myOddApptItem = myRecurrPatt.GetOccurrence(myDate)
'Save the existing subject. Change the subject and
'starting time for this particular appointment
'and save it.
saveSubject = myOddApptItem.Subject
myOddApptItem.Subject = "Meet NEW Boss"
newDate = #3/12/2003 3:30:00 PM#
myOddApptItem.Start = newDate
myOddApptItem.Save
'Release references to the appointment series
Set myApptItem = Nothing
Set myRecurrPatt = Nothing
'Get the recurrence pattern for the master
'AppointmentItem. Access the collection of
'exceptions to the regular appointments.
Set myItems = myFolder.Items
Set myApptItem = myItems("Meet with Boss")
Set myRecurrPatt = myApptItem.GetRecurrencePattern
Set myException = myRecurrPatt.Exceptions.Item(1)
'Display the original date, time, and subject
'for this exception.
MsgBox myException.OriginalDate & ": " & saveSubject
'Display the current date, time, and subject
'for this exception.
MsgBox myException.AppointmentItem.Start & ": " & _
myException.AppointmentItem.Subject
End Sub
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。