Outlook Mail Warning from Excel

breakoutfoo

Board Regular
Joined
Aug 5, 2008
Messages
73
Hi,

Is it possible to return the Yes/No result of the outlook mail warning to excel VBA so that I may display a 'Sent' or 'Not sent' message to the user?

Thanks

Andy
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,452
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Hi Andy

Assuming you are using code similar to that found here:
http://www.freevbcode.com/ShowCode.Asp?ID=159

If the user selects 'No' the code goes into error and you can trap that. On my PC I get an error number 287 (Application-defined or object-defined error). If the error is trapped then you can return a message saying the message wasn't sent, but if you don't get into the error section then you can put up an "all ok" message.

Following is a modified version of the code from the above link that shows my test:
Rich (BB code):
Public Sub SendOutlookMail()
 
On Error GoTo errorHandler
 
Dim oLapp As Object
Dim oItem As Object
 
Set oLapp = CreateObject("Outlook.application")
Set oItem = oLapp.createitem(0)
 
With oItem
   .Subject = "Test subject"
   .To = "me@mydomain.com"
   .body = "Test message"
   .Send
End With
 
Set oLapp = Nothing
Set oItem = Nothing
 
MsgBox "The message was sent!", vbInformation, "Success!"
 
Exit Sub
 
errorHandler:
Set oLapp = Nothing
Set oItem = Nothing
If Err.Number = 287 Then
    MsgBox "The e-mail was not sent", vbCritical, "User error!"
Else
    MsgBox Err.Description, vbCritical, "Error : " & Err.Number
End If
 
End Sub

Andrew
 
Upvote 0

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi Both,

Not sure how much the code differs but I normally go for Ron de Bruins mailers found here and with these the user doesn't get the option to send the mail, it just goes. You don't get the "Another Application is trying to access Outlook" message.

Not sure if this helps or not
 
Upvote 0

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi Andrew,

Not a problem, I was only speculating, I've not come across Express Click Yes before and have very minimal experience of using Ron's code but on the three or four times I've used it I've seen that you don't get that anoying box pop up.

I shall check your link out.

Cheers.
 
Upvote 0

Forum statistics

Threads
1,191,131
Messages
5,984,845
Members
439,918
Latest member
engrnoir

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
Top