How can I change the mail format to html in a macro?
The behavior when you change the format of the reply mail from Plain Text
using an Outlook macro is not the same as when using the Text Format / Format / HTML menu.
My original outgoing mail, immediately after clicking the Reply button, looks like this:
If I then click the HTML button, it stays exactly the same except for the format change in HTML, after which I can change the font, size, etc.
But if you instead change the format in the macro with ...BodyFormat = olFormatHTML
(see full code below), then
- the leading empty line is removed.
- mail headers are removed.
- font changes
Times New Roman 10
Is there a way to get the UI behavior from a macro? Do I need to delete the text before changing the format and then re-insert it? How?
The body of the macro looks like this:
Sub ChangeToTextStyle()
Dim objItem As Object
Dim objMail As MailItem
On Error Resume Next
Set objItem = Application.ActiveInspector.CurrentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
Set objMail = objItem
objMail.BodyFormat = olFormatHTML
End If
End If
End Sub
UPDATE
Minor issues after Eugene's answer:
Inserting objMail.Save
before the format change retains the title and blank lines, but the font changes to Times New Roman instead of Lucida Console, which is what I set in preferences for composing and reading plain text mail. The original text is displayed at 10pt and the cursor is displayed at 12pt. How do I - Change the font to Lucida Console 9.5pt
for all text in the mail? - Change the color of the cursor to wdDarkRed
?
source to share
Try ExecuteMSO - http://msdn.microsoft.com/en-us/library/office/ff862419(v=office.15).aspx
"Works with controls that are built-in buttons ..."
Sub ChangeToTextStyleHTML()
Dim objItem As Object
Dim objMail As mailitem
On Error Resume Next
Set objItem = Application.ActiveInspector.currentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
ActiveInspector.CommandBars.ExecuteMso ("MessageFormatHtml")
End If
End If
End Sub
There are other ways as well, but you can see MessageFormatHtml, IdMso, as the last bit of text when you hover over a selection while adding an inline button for the quickbar or ribbon.
source to share
Otherwise, you can just set up the html email by replacing the code like this:
Sub ChangeToTextStyle()
Dim objItem As Object
Dim objMail As MailItem
On Error Resume Next
Set objItem = Application.ActiveInspector.CurrentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
Set objMail = objItem
.HTMLBody = .HTMLBody
End If
End If
End Sub
This worked for me.
source to share