简体   繁体   English

如何在 Excel vba 中修改 Outlook 约会的重复次数?

[英]How do I get modified recurrences of Outlook appointments in Excel vba?

I am trying to write a macro in Excel that reads in all of my calendar appointments for today and calculates the total time spent in these appointments.我正在尝试在 Excel 中编写一个宏,该宏读取我今天的所有日历约会并计算在这些约会中花费的总时间。 The problem I seem to be running into is that all of my appointments are recurring appointments, and some instances have the date or the start time modified.我似乎遇到的问题是我的所有约会都是定期约会,并且某些实例的日期或开始时间已被修改。 My code is filtering, but not how I would expect it to, and I think it is because of the modified recurrences.我的代码正在过滤,但不是我期望的那样,我认为这是因为修改了重复。

How do I get the details of today's recurrences only?如何仅获取今天重复的详细信息?

Dim olApp As Object
Dim olNS As Object
Dim olFolder As Object
Dim olApt As Object
Dim olResults As Object
Dim olItem As Object
Dim NextRow As Long
Dim mydate, sdate, edate As Date
Dim sFilter As String
Dim i As Long
Dim dtEnd As Date



mydate = Date

Set olApp = CreateObject("Outlook.Application")

Set olNS = olApp.GetNamespace("MAPI")

Set olFolder = olNS.GetDefaultFolder(9)

sdate = mydate + 6 / 24
edate = mydate + 17 / 24
sFilter = "[Start] >= '" & Format(sdate, "ddddd h:nn AMPM") & "'" & " AND [Start] < '" & Format(edate, "ddddd h:nn AMPM") & "'"

olFolder.Items.IncludeRecurrences = True
olFolder.Items.Sort ("[Start]")
Set olResults = olFolder.Items.Restrict(sFilter)

Hours = 0

If olResults.Count > 0 Then
    For i = 1 To olResults.Count
        Set olItem = olResults(i)
            Hours = Hours + olItem.Duration / 60
            Debug.Print olItem.Start
    Next i
End If

You must set properties on the same collection avoiding any calls to the Items property:您必须在同一个集合上设置属性,避免对Items属性的任何调用:

Dim folderItems as Outlook.Items 
Set folderItems = olFolder.Items
folderItems.IncludeRecurrences = True
folderItems.Sort ("[Start]")
Set olResults = folderItems.Restrict(sFilter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM