How to open Outlook from Access in HTML format?

Hi Experts,

The following code opens an Outlook message in plain text format.
Sub SendEmail()
    Dim objOL  As Object
    Set objOL = CreateObject("Outlook.Application")
    
    Dim email  As Object
    Set email = objOL.CreateItem(0)    '0 = olItemEmail
    
    With email
        .To = "someone@somewhere.com"
        .Subject = "Test email"
        .Body = "This is a test email"
        .display  'use .Send to send the email immediately
    End With
End Sub

Open in new window

How can I have it opened in HTML format, the same way it opens when I start a new message using Outlook.

See attached.
Untitled.png
Untitled2.png
LVL 4
bfuchsAsked:
Who is Participating?
 
bfuchsConnect With a Mentor Author Commented:
Hi,

Actually was my mistake, I realized had used two methods to open outlook, one with docmd.sendobject and one as the above, so the send object was the plain text, while the code above indeed had it as HTML.

Thanks,
Ben
0
 
NorieConnect With a Mentor VBA ExpertCommented:
When I run that code it opens an Outlook email in HTML format just like in your 2nd image.

What happens if you change the code to use HTMLBody instead of Body?
Sub SendEmail()
    Dim objOL  As Object
    Set objOL = CreateObject("Outlook.Application")
    
    Dim email  As Object
    Set email = objOL.CreateItem(0)    '0 = olItemEmail
    
    With email
        .To = "someone@somewhere.com"
        .Subject = "Test email"
        .HTMLBody = "This is a test email"
        .Display  'use .Send to send the email immediately
    End With
    
End Sub

Open in new window

0
 
bfuchsAuthor Commented:
Hi,

Tried that already
Also tried .BodyFormat = 2
none works.

Perhaps it has to do with the Office version, see following
https://www.experts-exchange.com/questions/29071079/Docmd-SendObject-stopped-to-work-after-installing-Outlook-2016.html?anchor=a42431252¬ificationFollowed=202485751#a42431252

Thanks,
Ben
0
 
bfuchsAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.