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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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