首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >快速迭代Outlook约会项目

快速迭代Outlook约会项目
EN

Stack Overflow用户
提问于 2009-12-18 19:55:45
回答 2查看 21.1K关注 0票数 13

我已经编写了一个宏,它可以遍历用户的日历,并对满足特定条件的条目进行修改。

问题是,当日历非常大时,这需要很长时间。我似乎无法过滤约会,因为oAppointmentItems似乎会按创建时的顺序存储条目--顺序不一定与开始时相同。

我使用的代码是这样的:

代码语言:javascript
复制
Dim oOL As New Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oAppointments As Object
Dim oAppointmentItem As Outlook.AppointmentItem

Set oNS = oOL.GetNamespace("MAPI")
Set oAppointments = oNS.GetDefaultFolder(olFolderCalendar)

For Each oAppointmentItem In oAppointments.Items

    DoEvents
    ' Something here
Next

Set oAppointmentItem = Nothing
Set oAppointments = Nothing
Set oNS = Nothing
Set oOL = Nothing

除了删除DoEvents (这只意味着Outlook似乎锁定了用户),有没有什么方法可以通过应用某种过滤器来加快速度?例如,将来开始的约会。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-12-18 20:37:11

您可以使用Restrict进行过滤。请注意,日期的格式为月、日、年,并且它们被筛选为字符串,即使存储为日期:

代码语言:javascript
复制
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

Set olRecItems = olNS.GetDefaultFolder(olFolderTasks)
strFilter = "[DueDate] > '1/15/2009'"
Set olFilterRecItems = olRecItems.Items.Restrict(strFilter)


For i = 1 To olFilterRecItems.Count
  <...>

更多信息:http://msdn.microsoft.com/en-us/library/bb220369.aspx

票数 15
EN

Stack Overflow用户

发布于 2017-06-09 20:42:26

嘿,无法让任务工作,但这似乎可以在约会full explaination上工作

代码语言:javascript
复制
Dim myStart As Date
Dim myEnd As Date

myStart = Date
myEnd = DateAdd("d", 30, myStart)

Debug.Print "Start:", myStart
Debug.Print "End:", myEnd

'Construct filter for the next 30-day date range
strRestriction = "[Start] >= '" & _
Format$(myStart, "mm/dd/yyyy hh:mm AMPM") _
& "' AND [End] <= '" & _
Format$(myEnd, "mm/dd/yyyy hh:mm AMPM") & "'"
'Check the restriction string
Debug.Print strRestriction

Const olFolderCalendar = 9
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

Set oCalendar = olNS.GetDefaultFolder(olFolderTasks)

Set oItems = oCalendar.items
oItems.IncludeRecurrences = True
' oItems.Sort "[Start]" ' commented out  worked for me.. 
'Restrict the Items collection for the 30-day date range
Set oItemsInDateRange = oItems.Restrict(strRestriction)
Debug.Print oItemsInDateRange.Count
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1927799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档