AppointmentItem.GetRecurrencePattern 方法 (Outlook)

會傳回代表約會週期屬性的 RecurrencePattern 物件。

語法

expressionGetRecurrencePattern

表達 代表 AppointmentItem 物件的 變數。

傳回值

RecurrencePattern 物件,表示約會的週期屬性。

註解

如果目前沒有任何循環模式,就會傳回新的空白 RecurrencePattern 物件。

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

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

範例

這個 Visual Basic for Applications (VBA) 範例會使用 CreateItem 來建立 AppointmentItem 物件。 RecurrencePattern是使用GetRecurrencePattern方法針對這個專案取得。 在設定 RecurrencePattern 屬性、RecurrenceTypePatternStartDatePatternEndDate 後,這些約會現在成為一系列每日發生且為期一年的週期性約會。

使用GetOccurrence方法取得此週期性約會的一個實例,且更改這個實例的屬性時,就會建立Exception物件。 使用 GetRecurrencePattern 方法來存取與此系列相關聯的 Exceptions 集合,即可取得這一系列約會的例外狀況。 訊息方塊會顯示這個例外狀況的原始 SubjectOriginalDate ,適用于一系列約會,以及此例外狀況的目前日期、時間和主旨。

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

另請參閱

AppointmentItem 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應