Page Number

U

Ulf Nilsson

Hi,
If I search a document and a word is found on page 3, how
can I return the page number to the code? I have only
found how to return the page number the cursor is located
on, but not where the word is found.

/ Ulf
 
H

Helmut Weber

Hi Ulf,
like this:

Sub Test007
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ActiveDocument.ComputeStatistics (wdStatisticPages)
ResetSearch
With rDcm.Find
.Text = "comx"
If .Execute Then
MsgBox rDcm.Information(wdActiveEndPageNumber)
' found on page ....
End If
End With
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
.Execute
End With
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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