Application_ItemSend not accessed when sending email outside outlook (i.e. word or send to mail from

Status
Not open for further replies.
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
I have a working piece of code in the ThisOutlookSession that traps when the user is sending an email, except if the mail is sent from Word or Excel by using the Save&Send (as attachment or pdf) option.
I can't find any hint anywhere of how to make the code work also when doing it this way.
The mail is sent, but ItemSend event isn't fired can you please provide some help?
Code
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'll see what i can find out - AFAIK, no, but I know just enough to be dangerous. LOL

The reason it doesn't work is because the itemsend event catches the click on the Send button, and when a program sends it message its done differently and the send event isn't triggered.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Ok... is outlook running? i'm told it might work if outlook is open. (It didn't work in a quick test with Outlook 2010.)

If the other program supports vba, try catching the event in that application. Add a reference to the Outlook Object library, and ensure Outlook is running, then you'd get events like you do directly in Outlook. In order to get events of the Application object, declare a variable this way:

Private WithEvents OutlookApp as Outlook.Application
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
Ok... is outlook running? i'm told it might work if outlook is open. (It didn't work in a quick test with Outlook 2010.)

If the other program supports vba, try catching the event in that application. Add a reference to the Outlook Object library, and ensure Outlook is running, then you'd get events like you do directly in Outlook. In order to get events of the Application object, declare a variable this way:

Private WithEvents OutlookApp as Outlook.Application

Hi again,
thanks for your prompt support. The outlook version I use is 2007 and the aforementioned scenario took place with outlook opened. There is no possibility to run VBA on the other program. Is there any way to capture these events from within itemSend (from ThisOutlookSession)?

Thanks in advance for your help
 

sunil

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Hi can anyone help me the queries which i posted.

Regards,
Sunil
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
No, itemsend is the only event that would pick up on send. You might be able to do something with an inspector and remind the user to add a subject as soon as the message is opened, but that might be annoying if you remember most of the time.

Some of the group of developers that i asked were offline by the time I asked, so I might have some other ideas later in the day.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is from Outlook developer Ken Slovak:
Calls like that from Word, Excel, etc. use Simple MAPI to open the email item. You get a new Inspector in the Inspectors collection, but no NewInspector() event to handle. In addins I use a timer to check the Inspectors collection every once in a while to see if there are any Inspectors that haven’t been put into an Inspector wrapper collection. If I find one like that I wrap it, add it to the collection and then can handle any events on the Inspector or the item (like Send).

For VBA code you’d have to use a Win32 API system timer for something like that. Personally I’d handle it with an addin though.
It's definitely more than a simple macro and I don't have any code samples for timers. :(
 
Outlook version
Outlook 2007
Email Account
Exchange Server 2007
Hmmm, I see it is far more complicated than I initial thought. Thank you very much for your prompt response!!!

Anastasios
PS. If you come across with such sample of code, I'll welcome it!!! Thank you again!
 
Status
Not open for further replies.
Top