I use the code below to send an email from excel using Outlook:
Private Sub SendEmail()
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
newmsg.Recipients.Add ("name@domain.com; name2@domain.com; name3@domain.com")
newmsg.Subject = "Test Mail"
newmsg.Body = "This is a test email."
'newmsg.Display
newmsg.Send
End Sub
The code works very well, however I get the following error from Outlook when trying to send an email:
ErrorScreen http://im58.gulfup.com/GRENlB.png
It is strange that if I leave a new message open for two or three minutes, the names will be automatically resolved:
Work http://im74.gulfup.com/qmOYGQ.png
However, this does not suit me, since I do not want the message to be displayed before it is sent. I am looking for it to send as soon as I run the code.
Any suggestions or workarounds would be appreciated.
: " " Outlook, , .
UPDATE:
:
Private Sub SendEmail()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OlObjects = OutApp.GetNamespace("MAPI")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = ("name@domain.com; name2@domain.com; name3@domain.com")
.Subject = "Test Mail"
.Body = "This is a test email."
'.Display
.Send
End With
End Sub