PDA

View Full Version : better to run macro from Rule or Event?



Dr.K
07-04-2007, 08:00 AM
I'm writing a macro that processes incoming mail...

Would it be preferrable to trigger the macro from a rule, or to from the NewMail event?

Outside of having to Initialize_Handler to get the event to run, is there a difference?

mvidas
07-06-2007, 08:40 AM
Hi Dr K,

You wouldnt even have to initialize a handler if you're going to just use the _NewMail event. However if you do have OL2002+ then you could use the rules wizard. I only use ol2000 so I don't have any first hand experience, but I know there was another thread (http://www.vbaexpress.com/forum/showthread.php?t=13006) the other day where I learned the Outlook Security warning isn't triggered using event code but it is using the Rules method; that is the only time I've heard of it though.

If you can use a com addin or install ClickYes (both circumvent that security warning) then I'd say use a Rule for sure, as they're generally easier to narrow down what messages you're looking for and only require a single procedure. Events (like the _ItemAdd event of a Folder.Items object) can be quite useful too for a more general purpose, if you don't only want emails from aaa@xxx.com with a subject of "zzz". It really depends on what you're looking for and who will use it.
Want more general usage and distribution to different outlook (older) versions? Go with events, possibly even converting it to a COM addin for easiest distribution.
Only for you or specific (2002+) versions or specific usages? Use the rules method