Search code examples
htmlvbaoutlookms-wordhtml-email

VBA Change the Font of the mail


I created a vba code but the font and the size of the mail are incorrect. I would like Calibri 11 but it's Calibri 10 for the first line (Hello) and Verdana 10 for the rest. How to proceed?

Sub mail_outlook()

Dim OutApp As Object 
Dim OutMail As Object 

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail 
    .SentOnBehalfOfName = "xxxxxxxxxxxx"
    .Display 

    .To = "xxxxxxxxxxxxxxxxxx"
    
    .HTMLBody = "Hello, " & "<br>" & "<br>" & "Please find in attachment the Report." & "<br>" & "We remain available should you have any questions." & .HTMLBody
    .CC = "xxxxxxxxxxxxxxx"
    .BCC = "" 
    .Subject = "Report"

    
End With 

Set OutMail = Nothing 
Set OutApp = Nothing


End Sub  

Solution

  • You can specify the font size in the HTML:

    "<font style=""font-family: Calibri; font-size: 11pt;""> your content goes here</font>"
    

    See Change HTML email body font type and size in VBA for more information.

    Also you may use the Word object model for doing that programmatically. The WordEditor of the Inspector class returns an instance of the Document class from the Word object model which represents the message body. See Chapter 17: Working with Item Bodies for more information. For example, in Word you could use the following sequence of property calls:

    Selection.WholeStory
    Selection.Font.Size = 12
    Selection.Font.Name = "Georgia"