Last active
November 19, 2022 16:36
-
-
Save jilmun/6107dd0a2f53d3fdb719e9cfbc925453 to your computer and use it in GitHub Desktop.
Outlook VBA for formatting selected text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Add Microsoft Word XX.0 Object Library in Tools >> References | |
Public Sub FormatSelectedText() | |
Dim objItem As Object | |
Dim objInsp As Outlook.Inspector | |
Dim objWord As Word.Application | |
Dim objDoc As Word.Document | |
Dim objSel As Word.Selection | |
On Error Resume Next | |
'set current Outlook item | |
Set objItem = Application.ActiveInspector.CurrentItem | |
If Not objItem Is Nothing Then | |
If objItem.Class = olMail Then | |
Set objInsp = objItem.GetInspector | |
If objInsp.EditorType = olEditorWord Then | |
Set objDoc = objInsp.WordEditor | |
Set objWord = objDoc.Application | |
Set objSel = objWord.Selection | |
'set formatting | |
With objSel | |
.Font.Color = RGB(51, 51, 51) | |
.Font.Size = 10.5 | |
.Font.Bold = False | |
.Font.Italic = False | |
.Font.Name = "Verdana" | |
End With | |
End If | |
End If | |
End If | |
Set objItem = Nothing | |
Set objWord = Nothing | |
Set objSel = Nothing | |
Set objInsp = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment