Find and Replace feature when recording a Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I use the Find and Replace feature when recording a Macro? I am
trying to set up a macro that will find a series of like words in a document
and bold them for quick recognition.
 
Using the macro recorder to record a Find and Replace action produces some
really ugly code. This is how you would do it starting from scratch:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="yourword", MatchWildcards:=False, _
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.Font.Bold = True
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Back
Top