Reputation: 28761
The behavior when I change the format of a reply mail from Plain Text using Outlook VBA is not same as when using the Format Text/Format/HTML menu.
My original outgoing mail, just after hitting the Reply button looks as follows:
If I then click the HTML button it remains exactly same ,
except for changing the format to HTML after which I can change the font, size etc.
But if I instead change the format in a macro using
...BodyFormat = olFormatHTML
(see complete code at bottom) then
Times New Roman 10
Is there a way to get the UI behavior?
The macro body is as follows:
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 problems after following Eugene's answer:
Inserting objMail.Save
before changing the format preserves the header and blank lines but the font changes to Times New Roman instead of Lucida Console, which is what I have set in options for composing and reading plain text mail. The original text shows up in 10pt and the cursor is at 12pt. How do I
- Change font to Lucida Console 9.5pt
for all the text in mail?
- Change color at cursor to wdDarkRed
?
Upvotes: 3
Views: 4092
Reputation: 31
Otherwise you can just set the email into html format by replacing your code with the below:
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
That worked for me.
Upvotes: 0
Reputation: 9199
Try ExecuteMSO - http://msdn.microsoft.com/en-us/library/office/ff862419(v=office.15).aspx
"Works on 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 but you can see MessageFormatHtml, the IdMso, as the last bit of text when you hover over the selection when adding a built-in button for the Quick Access Toolbar or a ribbon.
Upvotes: 1
Reputation: 49455
It seems you need to Save the mail item and close the inspector window to apply the changes to the UI. Outlook doesn't reflect changes immediately in the UI. Sometimes you need to re-open the message.
Upvotes: 1