问题
I am trying to create a simple script to create a html message, and I would like to keep as much as possible of the default values.
In my case when I create a new message using Home ->
New mail it would always create a mail with default font [Calibri 11'], format text Html, and also with a signature.
If I use the function Application.CreateItem(olMailItem)
it creates the mail without issues.
However as soon as I declare an html body with .HTMLBody
it will overwrite the format: font [Times New Roman 12'], and also without a signature.
Even more surprising: if I use the 'trick' found online to keep the signature (see code bellow) then the font would be then overwritten to [Calibri 10'] (one point bellow the default)
Any recommendation/explanation?
Simple script to create an html mail (change of font + no signature) :
Sub TestMessage1()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.To = "test@domain"
.Subject = "test Mail"
.HTMLBody = "<p>Hello,<br><br>Could you please review this program<br><br>Regards,</p>"
.Display
End With
End Sub
write html mail with a signature (different change of font):
Sub TestMessage2()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.To = "test@domain"
.Subject = "test Mail"
.Display
.HTMLBody = "<p>Hello,<br><br>Could you please review this program<br><br>Regards,</p>" & objMsg.HTMLBody
End With
End Sub
回答1:
You need to paste the text or well-formatted HTML markup right after the <body>
tag and before the closing </body>
tag. In that case all format preferences will be preserved.
来源:https://stackoverflow.com/questions/43869628/keeping-default-outlook-format-when-creating-a-new-html-e-mail