Search code examples
vbaoutlookstring-formattingoutlook-2010

formatting email body using VBA


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


Solution

  • 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.