在 VBA 电子邮件中添加新行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25931716/
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 08:57:18  来源:igfitidea点击:

Add new lines in VBA email

excelvbaexcel-vbaexcel-2007html-email

提问by DannyBland

I'm trying to send an email automatically through Excel, but the new line commands aren't working! I've tried <br/>, vbCrLfand vbNewLine

我正在尝试通过 Excel 自动发送电子邮件,但新行命令不起作用!我试过了<br/>vbCrLf而且vbNewLine

.HTMLbody = "Hello" & vbNewLine & "Please find attached the above invoices and backup" & vbNewLine & _
            "Any queries please let me know" & vbNewLine & "Regards" & vbNewLine & Signature

It keeps just giving Hello Please find attached the above invoices and backup Any queries please let me know Regardsas one line!

它一直只是Hello Please find attached the above invoices and backup Any queries please let me know Regards作为一行给予!

回答by sabhareesh

May be you can try this instead: Use

也许你可以试试这个:使用

.HTMLbody = "Hello" & "<br>" & "Please find attached the above invoices and backup" & "<br>"

instead of vbnewline

而不是 vbnewline

回答by DannyBland

Try wrapping the text in some rudimentary HTML tags.

尝试将文本包装在一些基本的 HTML 标签中。

.HTMLbody = "<html><body><p>Hello</p><p>Please find attached the above invoices and backup.</p>" _
     & "<p>Any queries please let me know</p><p>Regards</p>" & Signature & "</body></html>"

This assumes that the signature is already HTML formatted at a paragraph level. (not tested; no guarantees)

这假设签名已经是段落级别的 HTML 格式。(未经测试;不保证)

回答by EdHunter

Unless you need the email to be HTML try using .body instead of .html.

除非您需要将电子邮件设为 HTML,否则请尝试使用 .body 而不是 .html。

If you need the email to be html then you need to ensure the entire text is formatted with Html tags. - The easiest way to do this is to have you html code in a cell in your workbook and then reference this cell.

如果您需要将电子邮件设为 html,那么您需要确保使用 Html 标签格式化整个文本。- 最简单的方法是在工作簿的单元格中放置 html 代码,然后引用该单元格。