0

I'm currently facing issues with putting HTML into VBA to send an e-mail. The formatting isn't coming out the way I want and I've been playing around with it.

The first part of my question is to get the font size to show up Outlook to what the code states. If the font size is 22, the size is being displayed in Outlook as 16.5 (the first line).

If the font size is supposed to be set to 11, the size is being displayed as 8.5.

I have the following questions for the table: The font is showing up as Times New Roman size 12 instead of Calibri size 11. Also, all of the "Column" and "Top Line" are not aligned to the top.

Is the syntax wrong?

.HTMLBody = "<html><center><p style='font-family:calibri;font-size:22'>" & "***<u>TEXT AT TOP</u> ***" & "</center></p>" & "<br>" & "<br>" & _
        "<p style='font-family:calibri;font-size:11'>" & "Good afternoon," & "</p>" & "<br>" & _
        "<p style='font-family:calibri;font-size:11'>" & "Attached please find your ... <strong> Please be advised.....</strong>" & "</p>" & _
         "<table><tr><td style='font-family:Calibri:align = top:font-size:11'>Column 1:</td><td style='font-family:Calibri'>Top Line</td></tr>" & "<br>" & _
        "<tr><td style='font-family:Calibri:align = top:font-size:11'>Column 2</td><td style='font-family:Calibri:align = top:font-size:11'>Top Line Row 2 <br> More text</tr></td>" & "<br>" & _
        "<tr><td></td><td style='font-family:Calibri:align = top:font-size:11'>Top Line Row 3 <br> More text </tr></td>" & "<br>" & _
        "<tr><td style='font-family:Calibri:align = top:font-size:11'>Column 3</td><td style='font-family:Calibri:align = top:font-size:11'>Top Line Row 4:</tr></td></table>" & "<br>" & _
        "<p style='font-family:calibri:font-size:11'>" & "Should you have any questions, or require any additional information, please do not hesitate to contact me anytime.  Thank you!" & "</p>" & "<br>" & _
        "<p style='font-family:calibri:font-size:11'>" & "Best regards," & "</p>" & _
         "<table><tr><td style='font-family:Calibri:font-size:12'><strong>Size 12 text</strong> | text <br> text </tr></td>" & _
         "<tr><td style='font-family:Calibri:font-size:12><strong>Name</strong></tr></td><table>"                   .Display 

Thank you!

2
  • Hold on here, no one ever came up with a COM type library that exposes functionality for generating correct HTML markup using objects? Getting ideas... #SeeANeed #FillANeed Commented Jul 11, 2017 at 16:43
  • Save yourself some grief, put the formatted HTML in a cell, then get the value of that cell for the HTMLBody. Typing it in VBE is not a lot of fun. Commented Jul 12, 2017 at 13:27

1 Answer 1

2

You have tones of errors in your HTML:

  • You're missing <body>.
  • You need to specify the unit for your font size. Something like 22pt or 22px.
  • You used colons : instead of semicolons ; in many places.
  • align=top is not CSS property, so move it out of style.
  • You cannot have <br> between your cells and rows.
  • </td> must come after </tr>, not before.
  • You didn't close your second table and your <html>.

Here is cleaned HTML:

"<html><body><center><p style='font-family:calibri;font-size:22px;'>" & _
"***<u>TEXT AT TOP</u> ***</center></p><br><br>" & _
"<p style='font-family:calibri;font-size:11px;'>" & _
"Good afternoon,</p><br>" & _
"<p style='font-family:calibri;font-size:11px;'>" & _
"Attached please find your ... <strong> Please be advised.....</strong></p>" & _
"<table><tr><td style='font-family:Calibri;font-size:11px;' align='top'>Column 1:</td>" & _
"<td style='font-family:Calibri;'>Top Line</td></tr>" & _
"<tr><td style='font-family:Calibri;font-size:11px;' align='top'>Column 2</td>" & _
"<td style='font-family:Calibri;font-size:11px;' align='top'>Top Line Row 2 <br> More text</td></tr>" & _
"<tr><td></td><td style='font-family:Calibri;font-size:11px;' align='top'>Top Line Row 3 <br> More text </td></tr>" & _
"<tr><td style='font-family:Calibri;font-size:11px' align='top'>Column 3</td>" & _
"<td style='font-family:Calibri;font-size:11px;' align='top'>Top Line Row 4:</td></tr></table><br>" & _
"<p style='font-family:calibri;font-size:11px;'>Should you have any questions, or require any additional information, please do not hesitate to contact me anytime.  Thank you!</p><br>" & _
"<p style='font-family:calibri;font-size:11px;'>Best regards,</p>" & _
"<table><tr><td style='font-family:Calibri;font-size:12px;'><strong>Size 12 text</strong> | text <br> text </td></tr>" & _
"<tr><td style='font-family:Calibri;font-size:12px;><strong>Name</strong></td></tr></table></body></html>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.