Add new lines in VBA email

本秂侑毒 提交于 2020-05-08 06:56:42

问题


I'm trying to send an email automatically through Excel, but the new line commands aren't working! I've tried <br/>, vbCrLf and 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 Regards as one line!


回答1:


May be you can try this instead: Use

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

instead of vbnewline




回答2:


Try wrapping the text in some rudimentary HTML tags.

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




回答3:


Unless you need the email to be HTML try using .body instead of .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.



来源:https://stackoverflow.com/questions/25931716/add-new-lines-in-vba-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!