View Single Post
  #2  
Old December 22nd 06, 04:51 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default OL2003 & VBA : How to find if a message was actually sent or canceled

Why use a loop? You might end up in that loop forever.

MailItem has a number of events it exposes: Send, Close, Open, etc. A
MailItem is displayed in an Inspector, which also exposed events such as
Activate and Close. In general one handles events in Outlook code to do what
you want.

If you instantiate a MailItem object declared WithEvents (I'm assuming here
you're using VBA or a variant of VB) you can handle any events on that item.
That would let you detect MailItem.Send or .Close. The Write event would
fire if the user saved the item.

Every item is displayed in an Inspector. oItem.GetInspector gets you that
Inspector object, which if declared WithEvents would let you handle
Inspector.Close, which might fire under certain circumstances where
Item.Close won't fire.

I'd spend some time reviewing the code samples at www.outloocode.com to see
how Outlook item and Inspector events are handled. You'll find code there
for whatever language you're coding in.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Michel S." wrote in message
...
Hello !

I'm developing an Excel application.

At some point, a message is built and the result is displayed to the user
who may, after reviewing it :
- click to send the message (after editing it if required)
- decide to cancel the message by closing the message window.

This message is an Outlook.MailItem object.

After I .Display the message, I'd like to enter a loop waiting for that
message to be processed by the user and record in a variable whether he
clicked on "Send" or not.

Note that since this user may work offline, the message may not actually
be sent but sitting in the outbox instead. For the application purpose,
this situation is the same as a sent message.

Any suggestions on how to achieve this ?

And, as a side question : if the user send or close the message, what
will happen to the .MailItem object ?

Thanks



Ads