How to create a "find" and "find next" macro?

N

Normus

I am working with a team of editors who asked me to create a macro that will
go through documents and find certain words that are commonly used
incorrectly (but not always), but giving them an opportunity to decide
whether or not to change each instance before moving on to the next.
Basically, it would go like this:

I want to find “xâ€, “yâ€, and “z†in any document I open. I may or may not
want to change the items once they are found. How do I create a macro that
lets me find the first instance of “xâ€, change it if I want to, find the next
instance of “xâ€, change it if I want to, etc. through to the end of the
document, then start over and search for the first instance of “yâ€, stop and
let me change it if I want to, find the next instance of “yâ€, stop and let me
change it if I want to, and so on?
 
G

Greg Maxey

Maybe something like this:

Sub FRScratchMacro()
Dim findText As String
Dim myRange As Range
Set myRange = ActiveDocument.Range
findText = InputBox("Enter text to find")
With myRange.Find
.Text = findText
.MatchWholeWord = True
While .Execute
myRange.Select
myRange.Text = InputBox("Replace with: ", "Process", myRange.Text)
myRange.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top