How to get list of entries some word with number of page where thisword was detected?

A

avkokin

Hello.
There is the some text which has one or more of the word "text". I
need to get list of all entries this word with number (or reference)
of page where detected this word. I have code (below), but it type
only last number of page. Where is my wrong? Thank you.

Sub poisk()
Dim a As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "text"
.Forward = True
.Wrap = wdFindStop
End With
While Selection.Find.Execute = True
a = Str(Selection.Information(wdActiveEndPageNumber))
Wend
Selection.EndKey Unit:=wdStory
Selection.InsertAfter vbCr
Selection.Collapse wdCollapseEnd
Selection.TypeText a & vbCr
End Sub
 
S

StevenM

To: Avkokin,

Instead of:

a = Str(Selection.Information(wdActiveEndPageNumber))

You need something like:

a = a & str(Selection.Information(wdActiveEndPageNumber)) & ", "

Steven Craig Miller
 
A

avkokin

Hello Steven. Thank's. I did so:
a = a & Trim(Str(Selection.Information(wdActiveEndPageNumber))) &
"," & vbCr

Sincerely, Anton.
 
S

StevenM

To: Avkokin,

Re: a = a & Trim(Str(Selection.Information(wdActiveEndPageNumber))) & "," &
vbCr

The function Str adds a leading space in the return string for the sign of
the number. Because of this, you added the function Trim which would strip
off the leading space. The function CStr is like Str except it doesn't have
the leading space.

a = a & CStr(Selection.Information(wdActiveEndPageNumber)) & "," & vbCr

Or simpler yet would be:

a = a & Selection.Information(wdActiveEndPageNumber) & "," & vbCr

Steven Craig Miller
 

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