Is There Any Better Index

H

Happy Trails

WORD 2007 - INDEX function just makes a formatted list with page
numbers. It would be nice if I could then click on a number and go to
that page. Is there a macro or anything that will produce an index
that will allow this?
 
D

Doug Robbins - Word MVP

If you run a macro that contains the following code when the selection in an
item in the index, it will move the selection to the page number that
appears in the index for that entry.

You could add this macro to the Quick Action Toolbar to facilitate its use:

Dim pagenum As Range
Set pagenum = Selection.Paragraphs(1).Range
pagenum.Start = pagenum.Start + InStrRev(pagenum.Text, " ")
On Error Resume Next
Selection.GoTo What:=wdGoToPage, Which:=pagenum.Text


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
H

Happy Trails

If you run a macro that contains the following code when the selection in an
item in the index, it will move the selection to the page number that
appears in the index for that entry.

You could add this macro to the Quick Action Toolbar to facilitate its use:

Dim pagenum As Range
Set pagenum = Selection.Paragraphs(1).Range
pagenum.Start = pagenum.Start + InStrRev(pagenum.Text, " ")
On Error Resume Next
Selection.GoTo What:=wdGoToPage, Which:=pagenum.Text

I appreciate the help, but this macro as it is written here doesn't do
anything in WORD 2007.
 
G

Graham Mayor

Try a minor modification

Dim pagenum As Range
Dim sName As Integer
Set pagenum = Selection.Paragraphs(1).Range
pagenum.Start = pagenum.Start + InStrRev(pagenum.Text, " ")
sName = pagenum.Text
On Error Resume Next
Selection.GoTo What:=wdGoToPage, _
Which:=wdGoToNext, _
name:=sName

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Happy Trails

Try a minor modification

Dim pagenum As Range
Dim sName As Integer
Set pagenum = Selection.Paragraphs(1).Range
pagenum.Start = pagenum.Start + InStrRev(pagenum.Text, " ")
sName = pagenum.Text
On Error Resume Next
Selection.GoTo What:=wdGoToPage, _
Which:=wdGoToNext, _
name:=sName

Rather than a minor patch that maybe works for certain instances of
indexes, in this case those without right-justified numbering, and
with a single page reference per word, I was thinking maybe bright
spark had actually created a new indexing function completely, with
hyperlinks, or at least a more comprehensive method of jumping to a
choice of page refs. and to the word or phrase on the page.

Maybe?
 
G

Graham Mayor

If a table of contents will work for you, rather than an index, the TOC page
numbers are linked to the relevant pages. Otherwise you are limited to a
macro solution.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Happy Trails

If a table of contents will work for you, rather than an index, the TOC page
numbers are linked to the relevant pages. Otherwise you are limited to a
macro solution.

A TOC is not an Index!

I did not mean to imply I was not NOT looking for a macro solution.
Was there something I said that implied that?

I would have thought that given Microsoft's extremely lame
implementation of their Index feature in WORD over the life of the
product that perhaps someone with much better skills than me at
writing VBA might have done something intelligent about this problem.
 
G

Graham Mayor

Don't shoot the messenger. We are not Microsoft employees, merely fellow
users giving of our time to help others.
I didn't say that a TOC was an index. I said that if a TOC would work for
you, it has hyperlink capabilties built in.
As for a macro solution Doug has already given you that. I don't know of any
better option that might work, but you can trawl the search engines just as
readily as I can.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Happy Trails

Don't shoot the messenger. We are not Microsoft employees, merely fellow
users giving of our time to help others.
I didn't say that a TOC was an index. I said that if a TOC would work for
you, it has hyperlink capabilties built in.
As for a macro solution Doug has already given you that. I don't know of any
better option that might work, but you can trawl the search engines just as
readily as I can.

Sorry to give offense..

Yes I realize the TOC has the hyperlinks - that's why I was puzzled
and unpleasantly surprised to find that the INDEX did not have them.

To clarify your suggestion, for me, a TOC works fine as a TOC, but
what I want is an INDEX that works as a useful item for pointy/clicky
usage.

Doug's solution is a little too simplistic to be much use due to the
restrictions previously mentioned, and I know I cannot expect that
someone is going to write a ton of new code just to respond to my
post, but as I said before, I would have thought someone would have
sorted this out years ago.

Thanks for your help; I guess it's something I'll have to work on on
my own.
 
D

Doug Robbins - Word MVP

Creating a really useful index is an artform, let alone one that has the
feature that you are after.

The trouble with probably all machine generated indexing functions, Word's
included, is that they list the page numbers of (virtually) occurences of
the indexed term and usually 99% of those occurences tell you no more about
the term than the index itself - the page number upon which it appears.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
H

Happy Trails

Creating a really useful index is an artform, let alone one that has the
feature that you are after.

The trouble with probably all machine generated indexing functions, Word's
included, is that they list the page numbers of (virtually) occurences of
the indexed term and usually 99% of those occurences tell you no more about
the term than the index itself - the page number upon which it appears.

I didn't suggest that I was looking for something that would go
through a document and automatically select what to index. As you
suggest, that might not be a good thing to do.

But I am dumbfounded that once the writer of a document has indicated
which occurences of which words & phrases he wants to index, the
software that builds the index cannot do a slightly better job of it.

By that I mean instead of merely a dumb list of the index entries, it
should build the index with hyperlinks so it is easy to go to the word
on the page when a reader clicks on the page in the index that he
wants to see.

Is this really asking too much?

These hyperlinks are built automatically with the TOC; why is it so
hard to do with an INDEX?

With such a feature it would be extremely efficient to examine all
occurences listed in the index one by one until the "right" one is
found.
 
D

Doug Robbins - Word MVP

It would be not too difficult to create a couple of macros, one of which
would be used to assign a bookmark name of the form x### to each term that
the author wanted to include in the index and then another one which would
build the index by iterating through all of the bookmarks in the document
and creating a two column table at the end of the document into the rows of
which for each bookmark of the form x### it would insert a { REF x### }
and a { PAGEREF x### \h } field and then sort the table by the column
containing the { REF x### } fields and then by the column containing the
{ PAGEREF x### \h } so that the terms were in alphabetical then page order
and it could even then "merge" the duplicate rows by combining all of the
{ PAGEREF x### \h } into the cell adjacent to the first { REF x### } field
and then delete the duplicate rows.

You would probably also want a third macro to take you back to the index
table, though if it was at the end of the document, just using Ctrl+End
would probably suffice.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
H

Happy Trails

You would probably also want a third macro to take you back to the index
table, though if it was at the end of the document, just using Ctrl+End
would probably suffice.

With VBA, can you not just save some sort of global variable for the
present location before you jump from the index, then your "return to
index macro" can return to the exact spot in the index that you just
left, probably to examine the additional references of the word you
are interested in, rather than simply jump to the beginning or end of
the index. Some of our indexes (indices?) could be as long as several
pages.
 
G

Graham Mayor

You could add a bookmark at the cursor location before jumping to the page,
then recall that bookmark to jump back again e.g.

ActiveDocument.Bookmarks.Add Range:=Selection.Range, name:="ReturnTo"

and to return

If ActiveDocument.Bookmarks.Exists("ReturnTo") = True Then
ActiveDocument.Bookmarks("ReturnTo").Select
End If


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jonathan West

Happy Trails said:
WORD 2007 - INDEX function just makes a formatted list with page
numbers. It would be nice if I could then click on a number and go to
that page. Is there a macro or anything that will produce an index
that will allow this?

Unfortunately Microsoft has never seen fit to make the page numbers in the
index hyperlinks. In principle, it would be possible to write a macro that
would identify an Index in the document, unlink it, identify all the page
numbers and create hyperlinks for them back to the source items on the
original pages.

This is perfectly possible, though it would be a detailed and fiddly macro
to write. But the net result would be that you no longer have an index that
you can automatically update using the F9 key.
 

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