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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I was going to write run the code; create the email. In the email, invoke the formatting dialog. The default font may not have a size 13 listed.

Decided to try it instead and using 13 in the code made a difference for me. Perhaps you are not referring to an email like the one I had to work with.
If it is the same, all I can suggest is to create the body, then display and not the other way around. I doubt that will help but it's worth a try.

1727535282436.png
 
Upvote 0
I was going to write run the code; create the email. In the email, invoke the formatting dialog. The default font may not have a size 13 listed.

Decided to try it instead and using 13 in the code made a difference for me. Perhaps you are not referring to an email like the one I had to work with.
If it is the same, all I can suggest is to create the body, then display and not the other way around. I doubt that will help but it's worth a try.

View attachment 117419
Hi Micron,

The problem is with font size 12, not with 13. Does font size 12 work for you also? Because then it's my computers problem i gues.. (font size 12 is there at the size options btw)

1727536198841.png
 
Upvote 0
Sorry about that. I did run it as you have it (just the part that creates the email itself) and when I checked the font was Calibri 12. Then I tested 13, which worked in spite of my font not having a size 13 in the list.

In that pic you should have highlighted a word then checked its size just in case it shows something different.
 
Upvote 0
Is it correct that you don't use a HTML signature? Because then it also works for me. But with a html signature loaded and combined with the text string, it won't set it at 12 points.
Also, if i don't use a signature and I try to execute it without the <div> element, the first line is font size 12 but the rest is 11. I tried it on two computers (1 with windows 10 and 1 with Windows 11).

1727543700057.png


Would you mind to execute the following code - without a signature - to see if "Dear" on your device also is in a bigger font size than the rest?

Here is the code:
VBA Code:
Sub SendEmailWithSignatureAndAccount()
    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 = "example@mydomain.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 = EmailBody & OutMail.HTMLBody
            OutMail.To = "to@example.com"
            OutMail.Subject = "subject of the mail"
            OutMail.Save
            
            Exit For
        End If
    Next OutAccount

    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
 
Upvote 0
Is it correct that you don't use a HTML signature?
Correct, I don't have one to use. I can't run your code without modifying it - I can't use the parts for accounts. I will try a modified version ASAP and let you know.
 
Upvote 0
OK, the lack of a signature really means testing is pointless (I think). Are you using a file (e.g. an image like a .jpg) or is it just formatted text? Either way, if you can post or provide a link I can download from I can keep trying. I suspect the solution involves concatenation. It might be helpful if you could post an image of the desired result.
EDIT - BTW, I see nothing in that code that governs font size so how would any part of it be larger than any other part? Am I missing something?
 
Upvote 0
Hi Micron, I just made little video explaining the problem. You can see it here:

Any idea what causes this crazy font issue?

Best regards,
Bas
 
Upvote 0
Apparently if it doesn't recognize a size, then it sets the default value, in your case it sets 11.
In my case, it does not recognize 11 and puts 10.

But try this way:
VBA Code:
OutMail.HTMLBody = "<BODY style=font-size:12pt>" & EmailBody & "</BODY>" & OutMail.HTMLBody

You can even set the font name:
VBA Code:
OutMail.HTMLBody = "<BODY style=font-size:12pt;font-family:Calibri>" & EmailBody & "</BODY>" & OutMail.HTMLBody

Try and comment.
 
Upvote 0
Apparently if it doesn't recognize a size, then it sets the default value, in your case it sets 11.
In my case, it does not recognize 11 and puts 10.

But try this way:
VBA Code:
OutMail.HTMLBody = "<BODY style=font-size:12pt>" & EmailBody & "</BODY>" & OutMail.HTMLBody

You can even set the font name:
VBA Code:
OutMail.HTMLBody = "<BODY style=font-size:12pt;font-family:Calibri>" & EmailBody & "</BODY>" & OutMail.HTMLBody

Try and comment.

Somehow it's still not working with size 12, but the font family part works very good. For instance I changed it to Arial. See below pictures.

picture 1: script as executed

1727613629829.png


Picture 2: result (font size = 11, not 12)
1727613741518.png


Any alternative things to try to get font size 12 to work also? I tried clearing the cache of outlook and excel also, just to be sure.
I also tried <p> instead of <body>, but that doesn't do the trick either.

Best regards, Bas
 
Upvote 0

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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