Getting pg# of field?

D

David Morris

If I have a Field object set to a field in my document, how can I find out what page it is on? I am trying to do this for an IndexEntry {XE} field. I thought I could get this through .Result, but word is saying the field doesn't have this property. Any other approaches?
 
J

JGM

Hi David,

Have you tried (after selecting your index field):

'_______________________________________
Dim CurrentPageNumber As Long

CurrentPageNumber = Selection.Information(wdActiveEndPageNumber)
MsgBox "The currently selected page number is: " & _
CurrentPageNumber & ".", vbInformation, "Page#"
'_______________________________________

?

HTH
Cheers!

--
'_______________________________________
Jean-Guy Marcil
(e-mail address removed)

David Morris said:
If I have a Field object set to a field in my document, how can I find out
what page it is on? I am trying to do this for an IndexEntry {XE} field. I
thought I could get this through .Result, but word is saying the field
doesn't have this property. Any other approaches?
 
J

JGM

Hi David,
If I have a Field object set to a field in my document, how
can I find out what page it is on? I am trying to do this for
an IndexEntry {XE} field. I thought I could get this
through .Result, but word is saying the field doesn't have
this property. Any other approaches?

How do you set the field object?
Can you post the relevant code?
What are you trying to do exactly?

Cheers!
 
D

David Morris

Thanks again for the help. Basically, I want to reconstruct the list of pages for an entry in the index, without updating the index or having to search for the entry in it.

The following works, but is slow, because I have to call the select method (as you suggested in your earlier message). Code to take care of \r indexentries is still to be added. Any other ideas?

Private Sub RefreshPageList()
Dim Out As String
Dim MyField As Field
Dim MyRange As Range
Dim InitialSelection As Range
Dim i As Long
Dim p As Long
Out = ""
Application.ScreenUpdating = False
Set InitialSelection = Selection.Range
For Each MyField In ActiveDocument.Fields
If MyField.Type = wdFieldIndexEntry Then
i = StrComp(Mid(MyField.Code, 6, Len(IndexEntries.Text)), IndexEntries.Text, vbTextCompare)
If i = 0 Then
If Out <> "" Then Out = Out & ", "
MyField.Select
p = Selection.Information(wdActiveEndPageNumber)
Out = Out & Str(p)
End If
End If
Next
PgList.Text = Out
ActiveDocument.Range(InitialSelection.Start, InitialSelection.End).Select 'Selection = InitialSelection
Application.ScreenUpdating = True
End Sub
 

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