Home » excel » excel – Add new lines in VBA email

excel – Add new lines in VBA email

Posted by: admin March 9, 2020 Leave a comment

Questions:

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!

How to&Answers:

May be you can try this instead:
Use

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

instead of vbnewline

Answer:

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)

Answer:

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.