创建每 2 年发生的定期约会

本主题显示了一个 Visual Basic for Applications (VBA) 代码示例,该示例创建一个以下面的模式进行的约会:

  • 于下午 2 点开始,并于下午 5 点结束。

  • 在 6 月份的最后一个星期一进行。

  • 每隔一年进行一次(例如,共进行三次)。

  • 2009 年 6 月 1 日生效。

该代码示例导致定期约会于 2009 年 6 月最后一个星期一(2009 年 6 月 29 日)、 2011 年 6 月的最后一个星期一(2011 年 6 月 27 日)和 2013 年 6 月的最后一个星期一(2013 年 6 月 24 日)的午 2 点至下午 5 点进行。 此约会将保存在默认日历中并会显示出来。

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 支持和反馈,获取有关如何接收支持和提供反馈的指南。