Excel VBA - Send Outlook Email from Template + added data

annyn

New Member
Joined
Apr 24, 2015
Messages
4
The following code works on Excel and Outlook 2010 but not on Excel and Outlook 365. Very simply, I just want to use an HTML Outlook template and add additional text to the beginning of the email based on one cell in my Excel worksheet. I've noticed in "Locals" that the variable objMail under "Body" the whole template in a string is there, but nothing is in "Body" for the same code using Excel 365. In 365 I get run-time error 287 (application-defined or Object-defined error) on the vtemplatebody = objMail.HTMLbody Line. I've been reading all kinds of code surrounding this issue but so much of it is more complicated and I don't understand it yet. Thanks in advance for any and all help!

VBA Code:
Sub MyHTMLMail()
 Dim OutApp As Outlook.Application
 Set OutApp = CreateObject("Outlook.Application")

 Dim objMail As Outlook.MailItem
 Set objMail = OutApp.CreateItemFromTemplate("C:\annyn\LH.oft")
 vtemplatebody = objMail.HTMLBody
 strBody = Range("E2").Value

 With objMail
 .BodyFormat = olFormatHTML
  .HTMLBody = strBody & "<br>" & vtemplatebody
 
 .Display
 End With
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Watch MrExcel Video

Forum statistics

Threads
1,130,399
Messages
5,641,921
Members
417,247
Latest member
Chitaah

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
Top