How can I know sent successfull or not using Outlook Application in VBA

Nay Min Naung

New member
Local time
Yesterday, 19:09
Joined
Nov 7, 2012
Messages
6
hi,
I send a mail in VBA using Outlook Application. That is sent if I have connection. But I want to know how to use that sent is successful or not. If anyone know about that please help me. The following code is I already written:

Dim objOutLookMsg As outlook.MailItem
Dim objOutLookMsgSent As outlook.Items
Set objOutLook = CreateObject("OutLook.Application")
Set objOutLookMsg = objOutLook.CreateItem(0)
With objOutLookMsg
.To = "my@gmail.com"
.CC = ""
.Subject = "(10:59 am)Hello, This is testing!!!!"
.Body = "This is in Body of Message"
.HTMLBody = "This is in HTML Body of Message"
'.Attachments.Add ("C:\MyFileToSend.Txt")
.Send
End With


I want to know mail sent successful or not.
Best Regard,
Nay Min Naung :)
 
At the top of your form code you need to put this

Code:
Private WithEvents olMailItem As Outlook.MailItem

when you set your email object you need to use the above.
Code:
Set olMailItem = objOutLook.CreateItem(0)

Now I would suggest you use two events. If you show the email and let them send it then you need to make sure they dont just close the email.
Code:
Private Sub olMailItem_Close(Cancel As Boolean)

And this is what you are looking for. This will fire once it is sent.
Code:
Private Sub olMailItem_Send(Cancel As Boolean)
 

Users who are viewing this thread

Back
Top Bottom