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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21248365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:35:18  来源:igfitidea点击:

formatting email body using VBA

vbastring-formattingoutlook-vbaoutlook-2010

提问by scb998

I have the following section of code, which is part of an automatic reply system im developing. As i understand it, it shouldformat 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

图片: 电子邮件截图

回答by L42

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

如果你使用,.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

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

希望这对你有用。
此外,您reportbody应该使用相同的格式HTML Tags

回答by Dmitry Streblechenko

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

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

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

您的常量喜欢vbCrLf不格式化 HTML。改用 HTML 标签,例如<br>换行。