View Single Post
 
Old 09-20-2018, 01:07 AM
Yotem189
Guest
 
Posts: n/a
Default Find and Replace Numbers Macro VBA in Microsoft Word

Hi all,

I'm trying to create a macro that will replace numerical values in only yellow highlighted text into 'x' for each character.
At the moment my code only works for all highlighted texts not just yellow.
How can I change this to make it only identify yellow highlighted texts?

Any help is greatly appreciated!


Code:
Application.ScreenUpdating = False

Lookfor = "1234567890"
Dim i As Long
For i = 1 To Len(Lookfor)
  Lookchar = Mid$(Lookfor, i, 1)
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
    .Text = Lookchar
    .Replacement.Text = "x"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = True
    .MatchAllWordForms = False
    .Highlight = True
End With
  Selection.Find.Execute Replace:=wdReplaceAll
Next

Application.ScreenUpdating = True
End Sub
Reply With Quote