我试图在Excel中编写一个宏,该宏读取今天所有的日历约会,并计算在这些约会中花费的总时间。我似乎遇到的问题是我所有的约会都是重复约会,并且某些实例的日期或开始时间已修改。我的代码正在过滤,但不是我期望的那样,这是由于修改后的重复发生。
如何仅获取今天重复发生的详细信息?
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
答案 0 :(得分:0)
您必须在同一集合上设置属性,避免对Items
属性进行任何调用:
Dim folderItems as Outlook.Items
Set folderItems = olFolder.Items
folderItems.IncludeRecurrences = True
folderItems.Sort ("[Start]")
Set olResults = folderItems.Restrict(sFilter)