none
Generating Email from Excel in Outlook via VBA RRS feed

  • Question

  • Hello guys,

    I'm trying to generate the emails via Excel with VBA, but I have some problems with the formatting.

    I would like to use .hmtlbody to format the Email, but it won't work.

    This is my code:

    <p style='font-size:16';font-family:Calibri>Dear Sirs or Madams</p>"

    but I only get the wrong formatting. It's Calibri, but it's 11.5 for the font size and I don't understand, why the formatting is wrong.

    Best regards

    Matthias

    Thursday, August 27, 2015 7:18 AM

Answers

  • >>>This is my code:

    <p style='font-size:16';font-family:Calibri>Dear Sirs or Madams</p>"

    but I only get the wrong formatting. It's Calibri, but it's 11.5 for the font size and I don't understand, why the formatting is wrong.

    According to your description, I have reproduced this issue with you provided this code "<p style='font-size:16';font-family:Calibri>Dear Sirs or Madams</p>".
    Apparently by setting the "font-size=16pt", It allows you to select a specific font size like you normally would in a text editor

    I get the correct formatting with below code, you could refer to it:

    Sub CreateHTMLMail()
     'Creates a new e-mail item and modifies its properties.
     
     Dim objMail As Outlook.MailItem
     
     'Create e-mail item
     
     Set objMail = Application.CreateItem(olMailItem)
     
     With objMail
     
     'Set body format to HTML
     
     .BodyFormat = olFormatHTML
     
     .HTMLBody = "<HTML><BODY><p style='font-size:16pt;font-family:Calibri'>" & "Your text here" & "</p></BODY></HTML>"
     
     .Display
     
     End With
    End Sub


    Friday, August 28, 2015 8:26 AM

All replies

  • Hello,

    I am moving your question to the Excel for developer's forum for better visibility.

    For the record, after I moved this question to this forum from VB.NET forum it still shows in the VB.NET forum and have indicated this in a moderator forum which in turn others have said this has happened to them. Any ways this is simply an FYI


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

    Microsoft Developer tools


    Thursday, August 27, 2015 8:34 AM
  • Hello Matthias,

    Outlook uses Word for rendering HTML markup. You can read about  supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following articles in MSDN:

    Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)

    Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)

    Thursday, August 27, 2015 10:48 AM
  • >>>This is my code:

    <p style='font-size:16';font-family:Calibri>Dear Sirs or Madams</p>"

    but I only get the wrong formatting. It's Calibri, but it's 11.5 for the font size and I don't understand, why the formatting is wrong.

    According to your description, I have reproduced this issue with you provided this code "<p style='font-size:16';font-family:Calibri>Dear Sirs or Madams</p>".
    Apparently by setting the "font-size=16pt", It allows you to select a specific font size like you normally would in a text editor

    I get the correct formatting with below code, you could refer to it:

    Sub CreateHTMLMail()
     'Creates a new e-mail item and modifies its properties.
     
     Dim objMail As Outlook.MailItem
     
     'Create e-mail item
     
     Set objMail = Application.CreateItem(olMailItem)
     
     With objMail
     
     'Set body format to HTML
     
     .BodyFormat = olFormatHTML
     
     .HTMLBody = "<HTML><BODY><p style='font-size:16pt;font-family:Calibri'>" & "Your text here" & "</p></BODY></HTML>"
     
     .Display
     
     End With
    End Sub


    Friday, August 28, 2015 8:26 AM