ERROR in coding - Pasting a specific data from excel

saloelrn1988

New Member
Joined
Apr 14, 2020
Messages
32
Office Version
  1. 365
Platform
  1. 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:

1642168638321.png


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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,223,919
Messages
6,175,368
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top