How can I tell when Rules have finished processing

2019-07-21 00:23发布

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条回答
SAY GOODBYE
2楼-- · 2019-07-21 01:01

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: enter image description here

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.

enter image description here

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

查看更多
登录 后发表回答