【发布时间】:2018-06-04 01:53:26
【问题描述】:
我正在尝试获取日历中发生在本月 5 日和下个月 4 日之间的所有约会(包括在那些日子发生的约会)。
Private Sub Application_Startup()
Dim oOL As New Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oAppointments As Object
Dim monthlyPats As Object
Dim oAppointmentItem As Outlook.AppointmentItem
'Set up date filter
Dim sMth As Date
Dim eMth As Date
sMth = dhFirstDayInMonth() + 3 '4th of this month
eMth = dhLastDayInMonth() + 4 '4th of next month
Dim eDate As String
eDate = "[End] < '" & eMth & "'"
Dim sDate As String
sDate = "[Start] > '" & sMth & "'"
'Restrict tasks based on date filters
Set oNS = oOL.GetNamespace("MAPI")
Set oAppointments = Session.GetDefaultFolder(olFolderCalendar).Folders("Portfolio analysis scheduler").Items.Restrict(eDate)
Set monthlyPats = oAppointments.Restrict(sDate)
End Sub
dhFirstDayInMonth() 和 dhLastDayInMonth() 函数获取当月的第一天和最后一天。
我在 2018 年 1 月 4 日有两个活动,一个是持续一整天的周期性活动,另一个是持续一整天的独立活动。
只有经常性事件才能通过。如果我让它们都重复出现,那么它们都会在monthlyPats 中被捕获,这就是我想要的。
【问题讨论】:
标签: vba filter outlook calendar appointment