Check to see if an Outlook Email was sent from Excel VBA

Joe_Canadian

New Member
Joined
May 23, 2008
Messages
33
I have a macro that opens and populates an Outlook Email, and displays it for editing. What I would like to do is have a way to determine if the user has sent it or not, and have some code run if they closed the email instead of sending it.

Rich (BB code):
Public Sub SendNotification()
Call AsgVar 'Routine which declares and intializes common variables
Dim strTMP As String, sTo As Variant, sCC As String, sBCC As String, sSubject As String, strbody As String
 
Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error GoTo Error_Handler
 
[Bunch of code assigning values to all of the strings]
 
            With OutMail
                .To = sTo
                .CC = sCC
                .BCC = sBCC
                .Subject = sSubject
                .Body = strbody
                .Attachments.Add "C:\BATTERY_ANALYSIS\" & strFileName
                If Not (ReplaceSheet = False Or ReplaceSheet = Null)Then .Attachments.Add RepDoc
                .Display
            End With
 
            Set OutMail = Nothing
            Set OutApp = Nothing
 
 
If user hit red close button instead of send then
 
     [code to run]
Else
    MsgBox ("Notification sent to " & strPlannerEmail & "@company.com")
End If
 
[different unrelated code]
 
end sub

Basically how do I do the bold line?
 
Oh I didnt realize that. So the close event is triggered from either hitting close or sending the email I assume?
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
It does - the Debug statement is incorrect.
Actually, the debug statement WAS correct. The solution as originally posted here was correct: When the user exits without sending an email, itm.Sent will be False, which is what you would expect of the _Close event. If however, the user presses 'Send', accessing tm.Sent returns an error ( -209452790, "The item has been moved or deleted"). Not necessarily intuitive, but a very clever method.
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top