Seeking page numbers for a particular word in a document

S

Sandy Porras

Can I locate the page numbers for a particular word in a
document? For example, if I'm looking for the
word "provisional" in a document, is there a feature that
tells me on what pages I can find that word in my
document?
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Sandy,

Use a macro containing the following code:

Dim msg As String
msg = "The word provisonal appears on the following pages: "
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="provisional", Wrap:=wdFindStop,
Forward:=True) = True
msg = msg & Selection.Information(wdActiveEndPageNumber) & ", "
Loop
End With
msg = Left(msg, Len(msg) - 2) & "."
MsgBox msg

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
G

Greg Maxey

Doug,

As the master you are, how would you adapt this macro to provided a user
interface for entering the sought after word? I mean like a pop up that
runs when you fire the macro asking the user to enter the desired word that
would define the "FindText= " value?





--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in (e-mail address removed)

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL
 
G

Greg Maxey

Doug,

One more question. How would you suppress multiple listings of the same
page in the message box display?



--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in (e-mail address removed)

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Greg,

Like this:

Dim Message, Title, myword, Msg, previouspage As Long
Message = "Enter the word that you are looking for." ' Set prompt.
Title = "Word Finder" ' Set title.
' Display message and title.
myword = InputBox(Message, Title)
Msg = "The word " & myword & " appears on the following pages: "
previouspage = 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=myword, Wrap:=wdFindStop, Forward:=True) =
True
If Selection.Information(wdActiveEndPageNumber) > previouspage Then
Msg = Msg & Selection.Information(wdActiveEndPageNumber) & ", "
previouspage = Selection.Information(wdActiveEndPageNumber)
End If
Loop
End With
Msg = Left(Msg, Len(Msg) - 2) & "."
MsgBox Msg

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
G

Graham Mayor

Nice one - but I think I would have been inclined to add
MatchWholeWord:=True to the find execution statement to eliminate false hits
on part words.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>


Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL
 
G

Greg Maxey

Graham,

That was the first thing I changed. Even I could figure that part out :).
Not a bad series of questions in this thread either yeah? I had to leave it
up to Doug to do the answering.
 
G

Graham Mayor

That's the best part of these newsgroups - picking one another's brains :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 

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