VBA .HTMLBody not working

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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
 
Upvote 0

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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