print the search results in Word

  • Thread starter Thread starter Willken
  • Start date Start date
W

Willken

How do I print the search results from Word that includes the page number for
each search result. Does anyone know a macro or does Microsoft Words have the
option?
 
The following macro will write the page number(s) of each occurrence of the
searched text to a new document.

Dim oDoc, oNewdoc As Document
Dim sText, sPage As String
sText = InputBox("Enter text to find")
Set oDoc = ActiveDocument
Set oNewdoc = Documents.Add
oNewdoc.Range.Text = "'" & sText & "' found on page(s) "
oDoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:=sText) = True
oNewdoc.Range.InsertAfter _
Selection.Information(wdActiveEndPageNumber) & ", "
Loop
End With
oNewdoc.Activate

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top