I'm very new to VBA and tying to write a code that would find and replace words in a word document. Here goes the code...
Sub callback(control As IRibbonControl)
stringReplaced = stringReplaced + "string to be searched"
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
ActiveDocument.TrackRevisions = True
.Text = "wATer"
.Replacement.Text = "Water"
.Wrap = wdFindContinue
.MatchWholeWord = True
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
ActiveDocument.TrackRevisions = False
Next myStoryRange
End Sub
It works fine, however, it also replaces the word "Water" even if it appears rightly in the document. I want the code to ignore the right instances and only concentrate on the incorrect instances. Not sure if the code needs an "If" clause.
In other words, if the document already has a instance of what's specified in "Replacement.Text", the code should ignore it. Please help