reubendayal
Senior Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi All,
I need help with converting this code in to a user defined funtion.
I am using an word document as a template to create an email. And then changing text in the email using bookmarks. But then some of the changed text I want to reformat. and in this instance only make the changed text's font colour red. And while the below works great if I repeat it each time, it make the code very long. I would like to convert this to a function so it can be used several times. I just do not know how to do it though.
I need help with converting this code in to a user defined funtion.
I am using an word document as a template to create an email. And then changing text in the email using bookmarks. But then some of the changed text I want to reformat. and in this instance only make the changed text's font colour red. And while the below works great if I repeat it each time, it make the code very long. I would like to convert this to a function so it can be used several times. I just do not know how to do it though.
Code:
objSel.Find.ClearFormatting
objSel.Find.Replacement.ClearFormatting
objSel.Find.Replacement.Font.Color = wdColorRed
With objSel.Find
.Text = "XXXX" ' intended text to be formatted'
.Replacement.Text = "XXXX" ' replaced and formatted text'
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With objSel
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With