快速遍历 Outlook 约会项目 [英] Iterating quickly through Outlook appointment items
问题描述
我编写了一个宏,它遍历用户日历并对满足特定条件的条目进行修改.
I've written a macro which iterates through a users calendar and makes modifications to entries that fufil a certain critera.
问题是当日历很大时,这需要很长时间才能完成.我似乎无法过滤约会,因为 oAppointmentItems
似乎在创建条目时存储条目 - 这不一定与它们开始时的顺序相同.
The problem is that when the calendar is very big, this takes a long time to do. I don't seem to be able to filter the appointments because oAppointmentItems
seems to store entries as they were created - which is not necessarily the same order as when they start.
我使用的代码是这样的:
The code I'm using is this:
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 似乎锁定了用户)有没有什么方法可以通过应用某种过滤器来加快速度?例如,未来开始的约会.
Short of removing the DoEvents
(which only means that Outlook appears to lock up to the user) is there any way I can speed this up by applying some kind of filter? For example, appointments which start in the future.
推荐答案
可以使用 Restrict 进行过滤.请注意,日期的格式为月、日、年,并且它们被过滤为字符串,即使存储为日期:
You can use Restrict to filter. Note that dates are in the format month, day, year and that they are filtered as strings, even though stored as dates:
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
这篇关于快速遍历 Outlook 约会项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!