Hello All,
I am trying to create a simple macro in Excel to use Outlook to send emails. I am using the code below however every time I reach the .send command I get the error "Error 287: Application-defined or object-defined"
Can you please help me?
Thanks!
Sub sendEmail()
On Error GoTo SubError
Dim olApp As Outlook.Application
Dim olMailItm As Outlook.MailItem
Set olApp = CreateObject("Outlook.Application")
Set olMailItm = olApp.CreateItem(0)
With olMailItm
.To = "mail@mail.com"
.Subject = "test"
.Body = "test"
.Send 'this command causes the error
End With
SubExit:
On Error Resume Next
Set olApp = Nothing
Set olMailItm = Nothing
Exit Sub
SubError:
Application.StatusBar = ""
MsgBox "Error: " & vbCrLf & Err.Number & " = " & Err.Description
Resume SubExit
End Sub