使用VBA格式化电子邮件正文

时间:2014-01-21 03:06:32

标签: vba string-formatting outlook-vba outlook-2010

我有以下代码部分,它是我正在开发的自动回复系统的一部分。据我了解,格式化电子邮件的正文,并附有换行符,但是,如附带的屏幕截图所示,它不会。有人会指出我出错了吗?

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

图像: Email Screenshot

2 个答案:

答案 0 :(得分:5)

如果您使用.HTMLBody,则应使用HTML Tags编写。{ 试试这个:

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

希望这适合你。
您的reportbody也应采用相同的格式HTML Tags

答案 1 :(得分:1)

嗯,您将HTMLBody属性设置为的值不包含任何HTML格式...

vbCrLf之类的常量不会格式化HTML。请改用HTML标签,例如<br>换行。