Can I capture the event ItemSend from a macro?

T

Totem

Hi,

I'm trying to capture the ItemSend event from a macro (not an add-in), but
for whatever reason it's not hitting it. Even after restarting Outlook
(2007), it does not kick in. Do I have to do something special?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox("hi")
End Sub

or do I have to write an add-in?

Thanks
 
T

Totem

I didn't have it under "ThisOutlookSession", so I've placed the code there
and it works now. Is this the only way? there's no way to have it in a
module so that I can easily share it with co-workers?
I'd like to know what's the easiest that I can share it with others and have
them update it as I provide them with a new version.

thanks
 
M

Mike YO_BEE B

Here is my code. I am a newbie at coding, but I found this and it works, but
I am not sure how to have this code start up automaticlly upon the start up
of OUTLOOK

Public WithEvents myOlApp As Outlook.Application

Public Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & "?"
If MsgBox(prompt, 4 + 16, "This is a Warning!") = vbNo Then
Cancel = True
End If

End Sub
 
K

Ken Slovak - [MVP - Outlook]

Put that code in the ThisOutlookSession class module. You don't need to
declare an Application object WithEvents in that class BTW. Then in the
Application_Startup event handler call your initialization.
 
M

Mike YO_BEE B

would it be something like this under the Class Modules ?

Public Sub Startup()
Set myOlApp = CreateObject("Outlook.Application")
End Sub

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & "?"
If MsgBox(prompt, 4 + 16, "This is a Warning!") = vbNo Then
Cancel = True
End If

End Sub
 
K

Ken Slovak - [MVP - Outlook]

No. It would be in the ThisOutlookSessionClass, you would never create an
Outlook.Application object (you use the intrinsic Application object) and
you use Application_Startup, as I said before.
 
M

Mike YO_BEE B

So do I play my code inside the Application_startup() like this

Public Sub Application_startup()

Private Sub msg_ItemSend(ByVal Item As Object, Cancel As Balloon)
Dim Prompt As String
Prompt = "Are you sure you want to send " & msg.To & " ?"
If MsgBox(Prompt, vbYesNo + vbInformation, "WARNING!!!!! You are
sending to a Distibustion Group") = vbNo Then
Cancel = True
End If
End Sub

End Sub
 
M

Mike YO_BEE B

This worked for me.

Thank you


Private Sub Application_Startup()

End Sub



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
 
M

Mike YO_BEE B

I was able to get the VBA Send Capture to work, but now I want to add some
filtering
Here is my copy for filtering one address, but I want to filter Multiple
addresses


Private Sub Application_Startup()

End Sub



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String

If Item.To = "TestDistList" Then

prompt = "Are you sure you want to send " & Item.To & "?"
If MsgBox(prompt, vbYesNo + vbExclamation, "Sample") = vbNo Then
Cancel = True
End If
Else
End If
End Sub
 
K

Ken Slovak - [MVP - Outlook]

So what's the question? If you want to filter on multiple email names or
addresses you will have to extend what you're doing now to handle all those
names or addresses.
 
K

Ken Slovak - [MVP - Outlook]

If Item.To = "TestDistList" Then

ElseIf Item.To = "whateverElse" Then

etc.

Or a Case...Select block, or a set of If's joined by OR clauses:

If Item.To = "TestDistList" OR Item.To = "Whatever" Then

There are lots of ways to test for more than 1 condition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top