saloelrn1988
New Member
- Joined
- Apr 14, 2020
- Messages
- 32
- Office Version
- 365
- Platform
- Windows
im trying to create a macro that will send an email to a specific receiver, with specific data is copied from excel to the body of the email, however I encounter an error upon running the macro below error i have encountered:
below is the coding I have use:
Sub Send_email()
'
' Send_email Macro
' Auto send email
'
' SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
' CREATE EMAIL OBJECT.
Dim objEmail As Object
Dim pageEditor As Object
Dim xinspect As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = Worksheets("Email error").Range("E3")
.CC = "jose@ek.com"
.Subject = Worksheets("Email error").Range("A1")
xmailbody = "Hi," & vbNewLine & vbNewLine & _
"Invoice below has been cancelled, please see below cancellation details." & vbNewLine & vbNewLine & vbNewLine & _
""
.body = xmailbody
Set xinspect = objEmail.getinspector
Set pageEditor = xinspect.wordeditor
Worksheets("Email error").Range("A2:m12").Copy
pageEditor.Application.Selection.Start = Len(.body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.pasteandformat (wdformatplaintext)
.display
End With
' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub
below is the coding I have use:
Sub Send_email()
'
' Send_email Macro
' Auto send email
'
' SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
' CREATE EMAIL OBJECT.
Dim objEmail As Object
Dim pageEditor As Object
Dim xinspect As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = Worksheets("Email error").Range("E3")
.CC = "jose@ek.com"
.Subject = Worksheets("Email error").Range("A1")
xmailbody = "Hi," & vbNewLine & vbNewLine & _
"Invoice below has been cancelled, please see below cancellation details." & vbNewLine & vbNewLine & vbNewLine & _
""
.body = xmailbody
Set xinspect = objEmail.getinspector
Set pageEditor = xinspect.wordeditor
Worksheets("Email error").Range("A2:m12").Copy
pageEditor.Application.Selection.Start = Len(.body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.pasteandformat (wdformatplaintext)
.display
End With
' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub