Limit replace macro to a specific page?

M

ML

Is there anyway to limit a replace macro to only run against a specific page
of a document? I want to look for certain words and reformat them if found
but only if on page 1 of my document.
 
D

Dave Lett

Hi ML,

You can use the following to limit the find/replace to the current page only:

Dim oRngToSearch As Range

Set oRngToSearch = Selection.Bookmarks("\Page").Range
With oRngToSearch.Find
.ClearFormatting
.Text = "Test"
.Font.Bold = True
With .Replacement
.ClearFormatting
.Text = "Replaced"
.Font.Bold = False
End With
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 

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