font size in outlook email (12 points doesn't work)

basb87

New Member
Joined
May 3, 2017
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have this script to create an email in outlook and it works fine, however....
If i merge the html body of the email with the standard signature and i try to set the font size to 12 it doesn't seem to work.

font size 11 and 13 work, but 12 doesn't. Isn't that strange? Does anyone know what's the problem here?

Hereby my script. It's nice and tiny:

VBA Code:
Sub SendEmailWithSignature()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim EmailBody As String
    Dim OutAccount As Object
   
    Set OutApp = CreateObject("Outlook.Application") ' Start Outlook application
    Set OutMail = OutApp.CreateItem(0) ' 0 create e-mail item
   
    For Each OutAccount In OutApp.Session.Accounts ' choosing the email account
        Debug.Print OutAccount.SmtpAddress
        If OutAccount.SmtpAddress = "info@example.com" Then ' going through the email accounts to find the right one
            Set OutMail.SendUsingAccount = OutAccount
            EmailBody = "Dear,<br><br>This is an example.<br><br>Best regards"
            OutMail.Display ' load email to make sure the standard signature is loaded also
            OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody ' combining the contents with the signature
            OutMail.To = "to@example.com"
            OutMail.Subject = "here comes the subject"
            OutMail.Save
           
            Exit For
        End If
    Next OutAccount

    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
 
And if you try with 12.1 or 12.2 or 12.5:

Rich (BB code):
      OutMail.HTMLBody = "<BODY style=font-size:12.5pt;font-family:Calibri>" & EmailBody & "</BODY>" & OutMail.HTMLBody

Also try by size number (1 to 7):
VBA Code:
      OutMail.HTMLBody = "<font face=""Calibri"" size=1> example 1 </font>" & _
                         "<font face=""Calibri"" size=2> example 2 </font>" & _
                         "<font face=""Calibri"" size=3> example 3 </font>" & _
                         "<font face=""Calibri"" size=4> example 4 </font>" & _
                         "<font face=""Calibri"" size=5> example 5 </font>" & _
                         "<font face=""Calibri"" size=6> example 6 </font>" & _
                         "<font face=""Calibri"" size=7> example 7 </font>" & _
                         OutMail.HTMLBody

Edit:
All of the above work for me. If they don't work for you, it may be your versions of excel - outlook
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
And if you try with 12.1 or 12.2 or 12.5:

Rich (BB code):
      OutMail.HTMLBody = "<BODY style=font-size:12.5pt;font-family:Calibri>" & EmailBody & "</BODY>" & OutMail.HTMLBody

Also try by size number (1 to 7):
VBA Code:
      OutMail.HTMLBody = "<font face=""Calibri"" size=1> example 1 </font>" & _
                         "<font face=""Calibri"" size=2> example 2 </font>" & _
                         "<font face=""Calibri"" size=3> example 3 </font>" & _
                         "<font face=""Calibri"" size=4> example 4 </font>" & _
                         "<font face=""Calibri"" size=5> example 5 </font>" & _
                         "<font face=""Calibri"" size=6> example 6 </font>" & _
                         "<font face=""Calibri"" size=7> example 7 </font>" & _
                         OutMail.HTMLBody

Edit:
All of the above work for me. If they don't work for you, it may be your versions of excel - outlook

They all work, but it's still not possible to get to font size 12 via these methods.
So strange that 12.5 works, but 12 doesn't.

Did you also manage to get font size 11 via this way? Intitially that did not work on your computer, right?
 
Upvote 0
I don't understand this concatenation:
OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody

I interpret that at first, .htmlbody is whatever it is (apparently a lot of xml). Then you're concatenating EmailBody to it, as in
"" & "Dear,<br><br>This is an example.<br><br>Best regards"
Then you concatenate the xml back again (but it's being done simultaneously and not in steps as I'm describing it), which seems to wipe out your EmailBody. When I run your modified code and test htmlbody I get a ton of xml and nothing else.
This is your code modified to eliminate account issues I would have in trying to run it
VBA Code:
Dim OutApp As Object, OutMail As Object, OutAccount As Object
Dim EmailBody As String

Set OutApp = CreateObject("Outlook.Application") ' Start Outlook application
Set OutMail = OutApp.CreateItem(0) ' 0 create e-mail item
 
EmailBody = "Dear,<br><br>This is an example.<br><br>Best regards"
OutMail.Display ' load email to make sure the standard signature is loaded also
OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody ' combining the contents with the signature
OutMail.To = "to@example.com"
OutMail.Subject = "here comes the subject"
 
 Set OutMail = Nothing
 Set OutApp = Nothing
A break point is set so that I can examine .htmlbody and this is what I get (not the comments about the number of lines deleted)
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/>
' 79 lines like that deleted...
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Link"/>
</w:LatentStyles>
</xml><![endif]--><style><!--
/* Font Definitions */
' 7 font lines removed for a font (can't recall which now)
' 7 more for Calibri
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
' 57 lines containing mso keywords/properties
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
' 27 lines removed for table properties
<div class=WordSection1><p ><o:p>&nbsp;</o:p></p></div></body></html>
Writing the code as I would:
VBA Code:
Dim OutApp As Object, OutMail As Object, OutAccount As Object
Dim EmailBody As String

Set OutApp = CreateObject("Outlook.Application") ' Start Outlook application
Set OutMail = OutApp.CreateItem(0) ' 0 create e-mail item
EmailBody = "Dear,<br><br>This is an example.<br><br>Best regards"
With OutMail
    '.HTMLBody = EmailBody '*****this makes no sense to me; nor does OutMail.HTMLBody that was in the next line
    .To = "to@example.com"
    .HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>"
    .Subject = "subject of the mail"
    .Display ' load email to make sure the standard signature is loaded also
End With

Set OutMail = Nothing
Set OutApp = Nothing
I get
?outmail.htmlbody
<div style='font-size:12pt'>Dear,<br><br>This is an example.<br><br>Best regards</div>
and I do not seem to have a problem controlling font size.
 
Upvote 0
I don't understand this concatenation:
OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody

I interpret that at first, .htmlbody is whatever it is (apparently a lot of xml). Then you're concatenating EmailBody to it, as in
"" & "Dear,<br><br>This is an example.<br><br>Best regards"
Then you concatenate the xml back again (but it's being done simultaneously and not in steps as I'm describing it), which seems to wipe out your EmailBody. When I run your modified code and test htmlbody I get a ton of xml and nothing else.
This is your code modified to eliminate account issues I would have in trying to run it
VBA Code:
Dim OutApp As Object, OutMail As Object, OutAccount As Object
Dim EmailBody As String

Set OutApp = CreateObject("Outlook.Application") ' Start Outlook application
Set OutMail = OutApp.CreateItem(0) ' 0 create e-mail item
 
EmailBody = "Dear,<br><br>This is an example.<br><br>Best regards"
OutMail.Display ' load email to make sure the standard signature is loaded also
OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody ' combining the contents with the signature
OutMail.To = "to@example.com"
OutMail.Subject = "here comes the subject"
 
 Set OutMail = Nothing
 Set OutApp = Nothing
A break point is set so that I can examine .htmlbody and this is what I get (not the comments about the number of lines deleted)

Writing the code as I would:
VBA Code:
Dim OutApp As Object, OutMail As Object, OutAccount As Object
Dim EmailBody As String

Set OutApp = CreateObject("Outlook.Application") ' Start Outlook application
Set OutMail = OutApp.CreateItem(0) ' 0 create e-mail item
EmailBody = "Dear,<br><br>This is an example.<br><br>Best regards"
With OutMail
    '.HTMLBody = EmailBody '*****this makes no sense to me; nor does OutMail.HTMLBody that was in the next line
    .To = "to@example.com"
    .HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>"
    .Subject = "subject of the mail"
    .Display ' load email to make sure the standard signature is loaded also
End With

Set OutMail = Nothing
Set OutApp = Nothing
I get

and I do not seem to have a problem controlling font size.

About this part:
VBA Code:
OutMail.Display ' load email to make sure the standard signature is loaded also
OutMail.HTMLBody = "<div style='font-size:12pt'>" & EmailBody & "</div>" & OutMail.HTMLBody ' combining the contents with the signature

The reason for the concatenation is that I want my signature to be added also, otherwise you'll just have an e-mail with plain text.

The whole point of the matter is that I want to have my email with signature in font size 12.
It's not a big problem, because I can just change the font size of my signature to 11, and then the font size of the dynamic email contents is the same as my signature, but it's just kind of frustrating me that I can't get font size 12 to work.

The reason I made the video without a signature is because the font size problem is occuring anyway. This happens when you merge the initial contents upon load (whether the signature is there or not).

BTW DanteAmor said that font size 11 did not work for him. I got the same on the laptop that I use for my employer. So, sometimes its font size 11 and sometimes is font size 12 that doesn't work.

I was hoping this was a known issue of the forum, since I would assume there are quite some people who use VBA to create emails with a signature automatically?

Best regards, Bas
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top