I'm currently working on a excel sheet which emails key information on a button push. The code that I'm using is
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
Dim StrSubject As String
Dim StrBody As String
StrSubject = "This is the subject line."
Strbody = "This is the body"
On Error Resume Next
.to = ""
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = Strbody
.BodyFormat = 3 '1=Plain text, 2=HTML 3=RichText
.Display 'or use .Send
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
I'm not used to this method and am more familiar with the DoCmd.SendObject but I'm trying to learn how to do processes in various ways.
When I used the DoCmd.SendObject though, if I cancel the email, the process comes to a halt.
In the method I'm using, when I cancel the email, the process continues. How do I halt the process in the above method? What I want is if someone presses the send button by accident, I want them to be able to cancel the email, and for the process to completely stop rather than doing the next bit.
I see that you are using Outlook to send the mail. If that is the case, I don't think this code will even matter in Excel, because you are now dealing with an Outlook problem, rather than an Excel scripting problem. Please tell me in what interface you are canceling the email.