使用限制查找指定时间段内的所有约会 [英] Find all appointments in specified period with Restrict

查看:59
本文介绍了使用限制查找指定时间段内的所有约会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取本月5日至下个月4日之间的日历中的所有约会(包括当日发生的约会).

I'm trying to get all appointments in a calendar occurring between the 5th of this month and the 4th of next month (including appointments that happen on those days).

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()函数获取当前月份的第一天和最后一天.

The dhFirstDayInMonth() and dhLastDayInMonth() functions get the first and last day of the current month.

我在2018年1月4日有两个事件,一个是持续一整天的周期性事件,另一个是持续一整天的独立事件.

I have two events on the 4th January 2018, one is a recurrent event that lasts all day and the other is a standalone event that lasts all day.

仅周期性事件通过.如果我让它们都反复出现,那么它们都会被捕获在我想要的monthlyPats中.

Only the recurrent event pulls through. If I make both of them recurrent then they both get captured in monthlyPats which is what I want.

推荐答案

事实证明,限制Outlook中的项目可能是一场噩梦,我确保IncludeRecurrences属性设置为True并按开始日期排序,这似乎可以技巧.

Turns out that restricting items in outlook can be a nightmare, I made sure the IncludeRecurrences property was set to True and sorted by start date, this seemed to do the trick.

此外,我使限制字符串同时执行了两项工作,似乎更加健壮:

Also, I made the restriction string do both jobs at once, seems to be a bit more robust:

Private Sub Application_Startup()

    Dim oOL As New Outlook.Application
    Dim oNS As Outlook.NameSpace
    Dim allAppointments As Object
    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() + 5 '5th of next month

    Dim rstDate As String
    rstDate = "[Start] > '" & sMth & "'" & " AND " & "[End] < '" & eMth & "'"

    'Restrict tasks based on date filters
    Set oNS = oOL.GetNamespace("MAPI")
    Set allAppointments = Session.GetDefaultFolder(olFolderCalendar).Folders("Portfolio analysis scheduler").Items
    allAppointments.IncludeRecurrences = True
    allAppointments.Sort "[Start]"

    Set monthlyPats = allAppointments.Restrict(rstDate)
    monthlyPats.IncludeRecurrences = True

End Sub

这篇关于使用限制查找指定时间段内的所有约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆