VBA .HTMLBody not working

Jasesair

Board Regular
Joined
Apr 8, 2015
Messages
211
Office Version
  1. 2016
I have the below code to send an email. I'd leave it working as is except I want to make some of the cell references bold. Have read many other threads about changing the .body to .htmlbody and changing the carriage returns to <br>. Unfortunately, I can't get anything to work, apart from the below which isn't HTML. Any assistance would be very much appreciated - don't be shy to let me know of any fundamental problems with my VBA attempt!

VBA Code:
Sub Email()

    Dim OutApp As Object
    Dim OutMail As Object

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = Range("f300")
        .CC = Range("f302")
        .BCC = Range("f304")
        .Subject = Range("f306")
        .Body = Range("f310") & vbLf & _
                "" & vbLf & _
                Range("f312") & vbLf & _
                "" & vbLf & _
                "" & vbLf & _
                Range("f314") & vbLf & _
                "" & vbLf & _
                "" & vbLf & _
                Range("f316") & vbLf & _
                "" & vbLf & _
                Range("f318") & vbLf & _
                "" & vbLf & _
                Range("f320") & vbLf & _
                "" & vbLf & _
                Range("f322") & vbLf & _
                "" & vbLf & _
                Range("f324") & vbLf & _
                "" & vbLf & _
        .Display
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,614
See if this helps.
VBA Code:
    Dim HTML As String
    HTML = "<p><b>" & Range("f310").Value & "</b><br>" & _
           Range("f312").Value & "<br><br>" & _
           Range("f314").Value & "<br><br>" & _
           "</p>"
and then .HTMLBody = HTML
 

Watch MrExcel Video

Forum statistics

Threads
1,122,567
Messages
5,596,908
Members
414,110
Latest member
docops

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