I'm currently working on an application based on Excel 2010 and VBA.
An important functionality of the application, is the ability to create and display
an Outlook mailitem to the user and record the contents of the created mailitem
when it is manually sent by the user (the send button of the displayed mailitem is clicked
by the user). To clarify:
1. The Excel application creates and displays to the user an Outlook Mailitem
2. The user alters the Mailitem and manually sends the Mailitem (clicks send)
3. The applications is supposed to catch the manual send event and create a copy
of the Mailitem
While most of this is relatively simple to implement - I use a class module and declarations
using the WithEvents statement as recommended - I can't seem to get the Send event to
trigger when the mailitem is manually sent. Note that the send event fires perfectly as it
should when the mailitem is programmatically sent using the Send method of the MailItem
So is there another and effective way of catching the send event of a created Mailitem
when it is manually sent?
I have attached an example of a Class Module (I would think ought to work) handling the
send event catching. The instance of the class module will of course not lose state after
creating the mailitem.
I hope someone is able to help.
Private WithEvents mOutlook As Outlook.Application
Private WithEvents mMailItem As Outlook.MailItem
Private Sub Class_Initialize()
Set mOutlook = New Outlook.Application
Public Sub CreateAndDisplayMailItem()
Set mMailItem = mOutlook.CreateItem(olMailItem)
.To = "email@example.com"
.Subject = "Test"
.Body = "Test Body"
Private Sub mMailItem_Send(Cancel As Boolean)
mMailItem.SaveAs "c:\test\test.msg", OlSaveAsType.olMSG
Debug.Print "Copy Saved"
Private Sub Class_Terminate()
Set mMailItem = Nothing
If Not mOutlook Is Nothing Then mOutlook.Quit
Set mOutlook = Nothing