item_send event

  • Thread starter Thread starter Gilles LEBRET
  • Start date Start date
G

Gilles LEBRET

Hi,
There is a little problem with Item_send event in OL2003.

Supose you have this code in your vba project :

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
msgbox "Hello"
end sub

You are expected to see "ok" every time you send a email. This code runs
fine when you compose a new mail directly with outlook.

Now, send a file via "Send to -> recipient" : open explorer file. With the
mouse, right-clic on a file and select : "Send to -> recipient"
A new message appears with you file attached. But If you send it, you do not
see "Hello" : Application_ItemSend event is not fired , even if Outlook
is running or not.


This problem do not occurs if a ComAddin is attached to Outlook : the
ComAddin is able to catch
Application_ItemSend when file is sent from explorer (even if Outlook is
running or not).

We would like to understand why a difference exists between VBA and Comaddin
..
Is there any workaround to force VBA to catch event when file is sent from
explorer ?

Thanks

Gilles Lebret
 
Send To uses Simple MAPI to open or send Outlook items. The Inspectors
opened as a result of a Simple MAPI command do not fire the NewInspector()
event, and are opened modally. They do add an Inspector to the Inspectors
collection, but there is no event that fires when the Simple MAPI Inspector
opens.

The way I usually handle this is to use a timer to check for Inspectors that
aren't already being handled by NewInspector(). That requires flags to
interlock handling so you don't handle an item twice or miss one, plus you'd
need wrapper classes that declared MailItems WithEvents so you can handle
their Send() events. I add each wrapper class to a collection to keep it
alive, updating the collection for each new Inspector and for each one that
closes.

I do however handle all this using addins. VBA code is just for prototyping
in Outlook or personal macros, it's not good for deploying or distributing
code.
 
Hello,
thanks for your answer.

one question about your sample code (wrapper class ) :

Where must I put this code ?

If it is in ComAddin, this won't help me because I already know that my
ComAddin catch event when using SendTO.
Could I put this wrapper class into outlook VBA ?
Thanks.
 
You can create wrapper classes in VBA just as you can in VB or C#. You can
add instances of the classes to a collection in VBA to keep them alive. Just
create a new class and add your WithEvents declarations to the class so it
can handle events for the Inspector and item.

The main problem is using timers in VBA code. You'd need to use VB-type code
to create and handle a Win32 system timer. There are examples of that for
VB6 at www.vbaccelerator.com, which can be adapted to VBA code.
 
Back
Top