I am trying to send email through VBA.
When the .Send wouldn't work, I found the Sendkeys method which works but the email has to display and then you can't touch the computer or you may disrupt the macro.
How can I make the .Send method work?
Dim OutApp As Object
Dim OutMail As Object
Dim count As Integer
EmailTo = Worksheets("Email Addresses").Range("A2")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate( _
Sheets("Start Here").Range("B25"))
On Error Resume Next
With OutMail
.To = EmailTo
'.CC = ""
'.BCC = ""
'.Subject = ""
'.Body = ""
'.Attachments.Ad' ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:est.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
'.Display
'SendKeys "^{ENTER}" ' <---this was the fix I found when .Send didn't work
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
See Question&Answers more detail:os