Access VBA send email with html body

Murray Brown
Murray Brown used Ask the Experts™
on
Hi
How do I modify the following VBA code so that I can send the body of the email
as html eg  

Dim oHBody As String = ""
            oHBody = oHBody & "<html><body><font size=3  color=" & sColor1 & " name = 'Calibri'>" & oIntro & "</font></body></html>"
            oHBody = oHBody & "<br>"


Sub SendReports(DisplayMsg As Boolean, Optional AttachmentPath)
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
    
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(0)
    
    With objOutlookMsg
        '.To = strTo
        'Subject = strSubject
        '.Body = strBody
        '.Attachments.Add strAttach
        '.Save
        '.Open
    End With
    Set objOutlook = Nothing
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer
Commented:
Please use the CODE button..

Use the BodFormat property to set the appropriate format and assign your body to the HTMLBody property.
John TsioumprisSoftware & Systems Engineer
Commented:
Just create a simple email in Outlook (HTML)...switch to source and copy that to a String variable...
Take a look at this Article : https://codekabinett.com/rdumps.php?Lang=2&targetDoc=howto-create-html-email-access-vba-outlook
A tag of "Microsoft Access" is missing here
President / Owner CARDA Consultants Inc.
Distinguished Expert 2018
Commented:
Instead of

.Body =  strBody

Open in new window


you use

.HTMLBody =  strBody

Open in new window


You may like to use a reusable function such as https://www.devhut.net/2010/09/03/vba-send-html-emails-using-outlook-automation/
NoahHardware Tester and Debugger
Commented:
Hi there! :)

You need something like this in your With/EndWith statement instead.

.HTMLBody = "<p><font face=""Calibri"" size=""3"" color=""red""><b>Your Message Here</b></font></p>

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial