PDA

View Full Version : How to get the index entries page number in word?



smksamy
08-24-2015, 07:19 AM
Hi friends,
currently I have one task related to index entries and index fields in word application.
some index entries start with one page end and end with next page beginning.

(e.g)14237

I selected that index entry as range, and I got that page number. using this code


Selection.Information(wdActiveEndPageNumber)


it gives the next page number, I want index entry beginning page number. anyone have better solution.

gmayor
08-24-2015, 08:54 PM
Use the part of the selection that is on the page you want to find e.g.

Selection.Characters(1).Information(wdActiveEndPageNumber)

smksamy
08-24-2015, 11:08 PM
Hai Gmayor, Thank u for your solution.
But still it give the next page number.


Selection.Characters(1).Information(wdActiveEndPageNumber)

give the same answer like
Selection.Information(wdActiveEndPageNumber)

gmayor
08-24-2015, 11:48 PM
The implication of that is that you don't have the field selected. If the field is selected, it works as indicated.
If the cursor is in the field, the following will work


Dim oRng as Range
Set oRng = Selection.Range
oRng.MoveStartUntil Chr(19), wdBackward
oRng.Start = oRng.Start - 1
oRng.Collapse 1
MsgBox oRng.Information(wdActiveEndPageNumber)

or use the code to select the field and then get the first character


Dim oRng As Range
Set oRng = Selection.Range
oRng.MoveStartUntil Chr(19), wdBackward
oRng.Start = oRng.Start - 1
oRng.Select
MsgBox oRng.Characters(1).Information(wdActiveEndPageNumber)