PDA

View Full Version : trigger code when currently open email is sent



urungus
12-03-2014, 09:49 AM
I have a VBA macro that runs in outlook and performs a few manipulations on the currently open email message. How can I trigger some additional code that will be run when the user subsequently sends (or closes) that specific message ?

I'm not sure if Application_ItemSend would work, since I don't know the identity of the specific item in advance -- the code should not run when *any* email is sent, it should only run when the currently open email is sent (or closed)

Thanks

westconn1
12-04-2014, 03:03 AM
you can set an item (or collection of items) with events
this must be at the top of an object module (either thisoutlooksession or a class module)

Public WithEvents xitm As MailItem

from some button or other code performed in the open message

Set xitem = ActiveInspector.CurrentItem

you can then put code in any of the events of xitm
probably best to set xitm to nothing when the code is finished, to prevent other events from firing later