formatting email body using VBA

30,045

Solution 1

If you use .HTMLBody then you should write it using HTML Tags.
Try this:

Dim EBody as String

EBody = "Please accept this email as confirmation that xxxx has received your road defect notification." & "<br>" _
    & "xxxxx will investigate and action your notification according to priority and to ensure public safety." & "<br>" _
    & "For further information, please phone xxxxx on 4221 6111 and quote reference number:" & "<br>" _
    & IDnumber & "Your original report can be seen below:" & "<br>" _
    & reportbody

With NewForward
    .Subject = "'TEST' Hazard report reciept number: HAZ" & IDnumber
    .To = strSender
    .BCC = "xxxxxxxxxxxx"
    .HTMLBody = Ebody
    .Send
End With

Hope this works for you.
Also your reportbody should be in the same format using HTML Tags.

Solution 2

Well, the value you are setting the HTMLBody property to does not include any HTML formatting...

Your constants like vbCrLf do not format the HTML. Use HTML tags instead, e.g. <br> for a line break.

Share:
30,045
scb998
Author by

scb998

Updated on June 23, 2020

Comments

  • scb998
    scb998 almost 4 years

    I have the following section of code, which is part of an automatic reply system im developing. As i understand it, it should format the body of the email with line breaks, but, as the attached screenshot shows, it doesnt. Can somebody point oput where im going wrong?

    With NewForward
                .Subject = "'TEST' Hazard report reciept number: HAZ" & IDnumber
                .To = strSender
                .BCC = "xxxxxxxxxxxx"
                .HTMLBody = "Please accept this email as confirmation that xxxx has received your road defect notification. xxxxx will investigate and action your notification according to priority and to ensure public safety. For further information, please phone xxxxx on 4221 6111 and quote reference number " & vbCrLf & IDnumber & vbCrLf & "Your original report can be seen below:" & vbCrLf & report_body
                .Send
            End With
    

    Image: Email Screenshot

  • L42
    L42 over 10 years
    glad it did :D you can also change font type, font color, font size using HTML Tags. If you like to learn more, you can start HERE. It also allows you to see the result of the code you generated.