PDA

View Full Version : Run code after email sent



g8r777
01-19-2016, 11:10 AM
I am looking for help with code to run after an email is sent by clicking the Send button.

I have tried various code found using Google searches. The code does not seem to do anything.

I think some of the issue comes from where to put the code whether it be in ThisOutlookSession or other modules.

Any assistance is appreciated. I am using Office365.

g8r777
01-19-2016, 11:57 AM
I have found code similar to the code below. The website this was taken from said to place in a Class module.

The code does nothing.



Public WithEvents myOlApp As Outlook.Application

Public Sub Initialize_handler()

Set myOlApp = 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 " & Item.Subject & "?"

If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then

Cancel = True

End If

End Sub

skatonni
01-19-2016, 04:42 PM
The code for ThisOutlookSession simplifies to:


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

g8r777
01-20-2016, 08:37 AM
The code still does not work. It's like the code isn't even running. I toggled a break point in the middle of the sub and then send an email. The debugger didn't pop up.

skatonni
01-20-2016, 03:11 PM
Perhaps you have not enabled macros in Outlook https://support.office.com/en-us/article/Enable-or-disable-macros-in-Office-files-12b036fd-d140-4e74-b45e-16fed1a7e5c6

g8r777
01-20-2016, 03:34 PM
I checked that. Macros were not enabled (recent new computer and forgot to enable them) but even after enabling the code still does not do anything.

g8r777
01-21-2016, 12:09 PM
The following code seems to work.

I have a dummy message box in there just to test the code. I will replace that for the code I really want.


Private WithEvents colInspectors As Outlook.InspectorsPrivate Sub Application_Startup()

Set colInspectors = Outlook.Inspectors

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


End Sub

Private Sub Application_Quit()

Set colInspectors = Nothing

End Sub