How can I tell when Rules have finished processing?

杀马特。学长 韩版系。学妹 提交于 2020-01-04 09:25:38

问题


I'm trying to find a way to trigger a VBA sub once, at the end of Outlook Rule processing. I'm currently using SyncEnd events, but this doesn't seem to work properly when first starting Outlook (the SyncEnd fires before Rules are run on the entire inbox, and mail items are not yet present in the folders where my function expects them to be).

Is a way to capture a "rules processing completed" event?


回答1:


All Outlook events are well documented within the VBE. Just press F2 to go into the Object Browser, then select the Outlook library (at the top in the drop-down menu, and then review all the available events.

Here are (for example) all available events for the Outlook application itself:

Unfortunately, you'll come to realize that there is no event which occurs after the rules. The available events NewMail and NewMailEx occur "[...] when new messages arrive in the Inbox and before client rule processing occurs." (https://msdn.microsoft.com/en-us/library/office/ff869202.aspx)

Yet, as @Om3r pointed out, you can make use of the fact that VBA runs one command at a time (line by line) and waits for the command to complete (before moving on to the next one). At least, that's how the VBA works unless you force it to process commands differently.

Hence, you can use the Application.NewMail or the Application.NewMailEx events to Execute the rules and then append the VBA commands you want to execute after the rules have been processed.

I sure hope this solves your problem. Let me know if you have any more questions.



来源:https://stackoverflow.com/questions/36940417/how-can-i-tell-when-rules-have-finished-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!