Question about Search and Replace to end of document

F

Frederick Lorca

I've researched this newsgroup's archives but didn't find a previous post or
reply that quite fit my situation.

I want to use VBA to begin searching at the top of page 2 of a document,
assuming there is a page 2, otherwise no search and replace is necessary. I
want to continue the search to the end of the document and quit. I've
considered programming VBA to insert a bookmark at the end of the document
where the search and replace feature could terminate.

I would like Search and Replace to prompt the user about whether and what
replacement text to enter. For example, if it finds the word "below," I
want it to ask the user about replacing it and what text to replace it with.


Frederick Lorca
 
H

Helmut Weber

Hi Frederick,

I'd simply select from page 2 to to the end of document
and then call the dialog wddialogeditreplace.
Like this, which makes an additional mouseclick necessary,
to answer the question, whether you want to continue
for the rest od the document.

Sub Test6789()
If ActiveDocument.BuiltInDocumentProperties("number of pages") > 1
Then
ResetSearch
With Selection
.ExtendMode = False
.GoTo what:=wdGoToPage, Which:=wdGoToAbsolute, Count:=2
Selection.End = ActiveDocument.Range.End
End With
Dialogs(wdDialogEditReplace).Show
ResetSearch
End If
End Sub
'---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub

Otherwise, you might need inputboxes or a userform
and lots of error-handling.
Things get complicated quickly.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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