建立每 2 年發生的週期性約會
這個主題會示範一個 Visual Basic for Applications (VBA) 程式碼範例,建立一個使用下列週期模式的約會:
開始於下午 2:00,結束於下午 5:00。
發生於六月的最後一個星期一。
每隔一年發生一次,在反覆三次之後結束。
開始日期為 2009 年 6 月 1 日。
此程式碼範例會產生一個週期性約會,從下午 2:00 到下午 5:00,於 2009 年 6 月的最後一個星期一 (2009 年 6 月 29 日)、2011 (2011 年 6 月 27 日) 及 2013 (2013 年 6 月 24 日) 發生。 約會會儲存在預設的行事曆中然後顯示。
Sub RecurringYearNth()
Dim oAppt As AppointmentItem
Dim oPattern As RecurrencePattern
Set oAppt = Application.CreateItem(olAppointmentItem)
Set oPattern = oAppt.GetRecurrencePattern
With oPattern
' Appointment occurs every n-th year (with n indicated by the Interval property).
.RecurrenceType = olRecursYearNth
' Appointment occurs on Monday.
.DayOfWeekMask = olMonday
' Appointment occurs in June.
.MonthOfYear = 6
' Appointment occurs on the 5th or last Monday (per the DayOfWeekMask property).
.Instance = 5
' Appointment occurs three times.
.Occurrences = 3
' Appointment lasts for 180 minutes each time.
.Duration = 180
' Appointment becomes effective on June 1, 2009.
.PatternStartDate = #6/1/2009#
' Appointment starts at 2 P.M.
.StartTime = #2:00:00 PM#
' Appointment ends at 5 P.M.
.EndTime = #5:00:00 PM#
' Appointment recurs every 2 years (per a RecurrenceType of olRecursYearNth).
.Interval = 2
End With
oAppt.Subject = "Recurring every 2 years YearNth Appointment"
oAppt.Save
oAppt.Display
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應