Automatic indexing from sections?

J

Jon

Has anyone written a macro which will allow the user to create index entries
from section headings, like the current automatic TOC? I have in mind
something which will:

Open the reference document (i.e. the document to be indexed). Select each
Level One section. Bookmark it and give it a name based on the section
heading. Create an index entry after the heading using the text of the
section heading. Thus the Level One heading



The Pleistocene Era



would generate a unique bookmark "The_Pleistocene_Era_AA", containing
everything from the heading paragraph down to the end of that section


and an index entry { XE "The Pleistocene Era" \t "The_Pleistocene_Era_AA"}



Each heading will be truncated as necessary before being used as a bookmark
entry. Non-legal characters will be omitted or changed into legal
characters. Each heading will be given a unique suffix - AA, AB, AC, etc -
so that if two identical headings occur in different sections they will be
distinguishable.


Repeat for Levels Two, Three, etc, as necessary.



Some fiddling will be necessary because of the limitations on bookmark
names, which as I understand it:



a. Can only contain letters, digits and underlines

b. Cannot start with a digit

c. Must be 40 characters or less

d. Must be unique

But given these limitations it should be possible to create a Word macro
which would do all this in one step.



If there's not an existing macro then I'll have a go myself, but I thought I
should try and avoid reinventing the wheel.



Jon.
 
C

Cindy M.

Hi Jon,
Has anyone written a macro which will allow the user to create index entries
from section headings, like the current automatic TOC? I have in mind
something which will:

Open the reference document (i.e. the document to be indexed). Select each
Level One section. Bookmark it and give it a name based on the section
heading. Create an index entry after the heading using the text of the
section heading. Thus the Level One heading
As far as I know, there is no existing macro (doesn't mean someone hasn't done
it, somewhere in the world...)

I just have some difficulty imagining WHY you'd want to create an Index that is
basically no different from a TOC?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Jon

Well, it would be in alphabetical order, for one thing.

But the idea is that this would be a starting point for a 'proper' index:
once the bookmarks and index entries are in place the user can go through
and edit them manually by adding double entries and cross-references and
making the terms more meaningful. It just saves the tedious labour involved
in manually selecting each chunk, bookmarking it and adding an index entry.

Jon.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Cindy:

Building an index by first tagging each heading is a pretty standard way of
starting an index in technical writing :) Assuming that the structure of
the book is not totally bad, it ensures that you get all of the main
concepts into the index in one go.

Jon: Yes, I did have a macro around for doing that, but it was written for
Word 2000 and it was too flaky for public distribution :)

Such a macro can be very slow in a large document. You can speed it up
substantially by creating your own "Collection" of Heading paragraphs.
However, that's fairly complex programming.

You may get just as good results by using the Find function to simply find
paragraphs with Heading 1, Heading 2, Heading 3 and Heading 4 styles (you
run the Find four times).

Each time you find one, retrieve the text of the selection (the Find
operation will stop with the paragraph selected) and throw that into your
index tag.

It's actually a tricky little macro to write, because on your second and
subsequent passes, you have to retrieve the most recent
previous-higher-level index tag. And THAT can be quite tricky/slow.

For a book of less than a thousand pages, you will find it a lot quicker to
do this by hand than to write the code for it :)

Hope this helps


Hi Jon,

As far as I know, there is no existing macro (doesn't mean someone hasn't done
it, somewhere in the world...)

I just have some difficulty imagining WHY you'd want to create an Index that
is
basically no different from a TOC?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :)

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410
 
J

Jon

Hi John and Cindy,

I've written a macro to do this for Heading levels 1 to 3 in Word XP - it's
a bit of a kludge but it seems to work. You can find it at

http://www.webindexing.biz/indexmacro.htm

Such a macro can be very slow in a large document.

But it can't possibly be slower than doing it by hand, can it?
You may get just as good results by using the Find function to simply find
paragraphs with Heading 1, Heading 2, Heading 3 and Heading 4 styles (you
run the Find four times). Each time you find one, retrieve the text of the
selection (the Find
operation will stop with the paragraph selected) and throw that into your
index tag.

No, because unless I'm missing something, this doesn't bookmark the range of
paragraphs between that Level X heading and the next Level X heading, does
it? If I put an index entry for 'cats' at the beginning of a Level 1 section
that extends from page 6 to page 15, it won't show up in the index as 'cats,
6-15' unless I have bookmarked that range and used the bookmark name in the
index entry with a \r code. My macro does that too.
It's actually a tricky little macro to write, because on your second and
subsequent passes, you have to retrieve the most recent
previous-higher-level index tag. And THAT can be quite tricky/slow.

I'm not sure what you mean by this. In my macro, for each 'chunk' the index
entry is taken from the text in the heading paragraph for that chunk.
For a book of less than a thousand pages, you will find it a lot quicker
to
do this by hand than to write the code for it :)

Yes, but I index for a living. If my clients decide to use embedded Word
indexing I could be doing this on five thousand pages per year.

While I'm at it, who decided that the index entry dialog box in Word XP
should only be long enough to display fourteen characters? Sheesh!

Thanks and regards,

Jon.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi John:

I've written a macro to do this for Heading levels 1 to 3 in Word XP - it's
a bit of a kludge but it seems to work. You can find it at

http://www.webindexing.biz/indexmacro.htm

Very impressive :) You obviously code faster than I do :)

You may find it a little quicker if you replace that array with a
user-defined collection. You will end up with an object that's a lot faster
to manipulate and can be addressed with a lot fewer lines of code.
But it can't possibly be slower than doing it by hand, can it?

Not quite :) I was actually thinking you had only "one" document to index
and was including the development time. If you are indexing documents for a
living, then the development time is sustainable.
No, because unless I'm missing something, this doesn't bookmark the range of
paragraphs between that Level X heading and the next Level X heading, does
it? If I put an index entry for 'cats' at the beginning of a Level 1 section
that extends from page 6 to page 15, it won't show up in the index as 'cats,
6-15' unless I have bookmarked that range and used the bookmark name in the
index entry with a \r code. My macro does that too.

You're right. I have given up on conflated page ranges in an index. The
reader doesn't give a damn how many pages there are in the range, they just
want to know where it starts. And they're a fiddle and a pain to do :)
I'm not sure what you mean by this. In my macro, for each 'chunk' the index
entry is taken from the text in the heading paragraph for that chunk.

Chapter 3 Installation
Installing the transport
Installing the Conduit
Installing filters
Canon filter
Sony filter
HP filter

Chapter 4 Customisation

Index

Installation 37
Transport 38
Conduit 42
Filters 44
Canon 45
HP 51
Sony 47
While I'm at it, who decided that the index entry dialog box in Word XP
should only be long enough to display fourteen characters? Sheesh!

{Chortle} One of the "Things we never got around to fixing" :) It's been
that way since Word 6, and I guess they haven't been into the code since
then to change it.

Cheers

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410
 

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