• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB code : send emails to Outlook Error

Monty

Well-Known Member
Hello Experts.

Question is real simple.
user job is to send an email from excel to outlook version 2013.

1) This below code works perfectly at home pc as outlook 2013 is connected to SMTP/POP server.

2) The same code does not work at office desk as outlook 2013 is connected to exchange server.

Error No 287 Application defined or object defined error.

Below code for quick references.

Code:
Sub Mail_Outlook()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "Hi there"

    On Error Resume Next
    With OutMail
        .To = "Monty@gmail.com
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody
        .Send  ' Error at this line
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Last edited:
Back
Top