View Single Post
 
Old 10-20-2015, 06:30 AM
rsrasc rsrasc is offline Windows 7 64bit Office 2010 64bit
Competent Performer
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default ".Replacement.Font.Color" Possible Combination

Hi all,


Code:
Sub FormatLetterA()
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
        .Text = "Answer (A) "
        .Replacement.Text = ""
        .Replacement.Font.Bold = True
        .Replacement.Font.Italic = False
        .Replacement.Font.Color = 12611584
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWholeWord = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub FormatLetterB()
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
        .Text = "Answer (B) "
        .Replacement.Text = ""
        .Replacement.Font.Bold = True
        .Replacement.Font.Italic = False
        .Replacement.Font.Color = 12611584
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWholeWord = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub FormatLetterC()
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
        .Text = "Answer (C) "
        .Replacement.Text = ""
        .Replacement.Font.Bold = True
        .Replacement.Font.Italic = False
        .Replacement.Font.Color = 12611584
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWholeWord = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub FormatLetterD()
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
        .Text = "Answer (D) "
        .Replacement.Text = ""
        .Replacement.Font.Bold = True
        .Replacement.Font.Italic = False
        .Replacement.Font.Color = 12611584
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWholeWord = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub


I have the above code in a macro and would like know if they could be combined in one.

I tried several options but I couldn't get them to work.

For example, the below code will only highlight the second option (.Text = "Answers (B), (C), and (D)") but not both.

Any help is appreciated. Thanks!!!

Code:
Sub FormatAllLetters()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Answers (A), (C), and (B)"
.Replacement.Text = ""
.Text = "Answers (B), (C), and (D)"
.Replacement.Text = ""
.Replacement.Font.Bold = True
.Replacement.Font.Color = 12611584
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote