Search code examples
htmlexcelvbaemailoutlook

Size of font is not applied correctly on the body of the new email message outlook


I am using a custom code to generate email on outlook from excel.
The code works, But I seek to set a custom size of font used on the body.
As in the below code , I set font properties ( type , size & color ) , and it applied correctly except the size.
If I set the size on code = 5 but in the email itself it became = 18.
If I set the size on code = 6 but in the email itself it became =24.
Also ,why vbTab has no effect at all (it does not insert a tab at beginning of the second line).
In advance, grateful for all your help.

Sub Send_Email()
 
    Dim objOutlookApp As New Outlook.Application
 
    Dim myEmail As Outlook.MailItem
     Set myEmail = objOutlookApp.CreateItem(olMailItem)
      myEmail.BodyFormat = olFormatHTML
 
    myEmail.Display
 
    Dim Strbody As String
 
    Strbody = "<h5>Dears,</h5>" & vbCrLf & vbTab & _
              "<font face = Times New Roman size= 5 font color=Brown>This a test string</font>"
 
    myEmail.HTMLBody = Strbody & myEmail.HTMLBody
 
End Sub

Solution

  • Make sure that you deal with a well-formed HTML markup, otherwise you will get unpredictable results in Outlook. For example, you could use something like that:

    strbody = "<p style=font-size:11pt;font-family:Calibri>Good Morning!<p>"