You need to add a VBA Project reference to the Word object library, or define those constants such that Outlook can understand what the true values of wdColorBlue
and wdYellow
are.
When I did that, your code had the desired effect (but if you add a reference then you can't use Word
as a variable name)
Here's what worked for me (more or less - I was at work when I tested, but not there now...)
The Collapse
part works fine in Word, so should work also in Outlook.
Sub ChangeSelectedFontBold14HiYellow()
Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Set insp = Application.ActiveInspector
If insp.CurrentItem.Class = olMail Then
Set msg = insp.CurrentItem
If insp.EditorType = olEditorHTML Then ' outlook 2003
Set hed = msg.GetInspector.HTMLEditor
Set rng = hed.Selection.createRange
rng.pasteHTML "<b><font style='color: blue; background: yellow; font-size: 14pt;'>" & rng.Text & "</font></b>"
End If
If insp.EditorType = olEditorWord Then ' outlook 2013
Set hed = msg.GetInspector.WordEditor
Set appWord = hed.Application
Set rng = appWord.Selection
rng.Font.Size = 14
rng.Font.Color = wdColorBlue
rng.Font.Bold = True
rng.Range.HighlightColorIndex = wdYellow
rng.Collapse Direction:=wdCollapseEnd 'UNTESTED, but something like this...
End If
End If
Set appWord = Nothing
Set insp = Nothing
Set rng = Nothing
Set hed = Nothing
Set msg = Nothing
End Sub