TOC Macro

S

Sam

I am using Word 97.

I need to create a macro that creates a contents page.

Basically I will type the word 'Contents', right tab to
the right margin and type 'page'. Press return and then
to 'insert' 'table of contents'. I click on the options
box and make sure that every single style is deselected
and that the only style ticked is my 'section headings
style'. I then 'okay' this I end up with exactly what I
want.

The problem occurs when I play back the macro. Everything
is fine except it adds in loads of extra headings in my
TOC which didn't appear while recording. I can go into the
TOC options again and remove the ticks but it defeats the
point of trying to speed up the process with macros.

Does anyone know what I'm doing wrong?

Thank you
 
S

Shauna Kelly

Hi Sam

If your aim is to make it easy to add a ToC to a document, then I
wouldn't use a macro; I'd use an AutoText. To do that, create your
contents page as you want it to be. Select the text and do Insert >
AutoText. Give your AutoText a name (eg "ContentsPage"). If you want it
to be available to all documents, choose to save it in normal.dot. If
you want it available only to documents in a particular template, choose
that template.

Now, whenever you want to insert your contents page, type ContentsPage
and press F3.

However, if you need to use a macro for some other purpose, bear in mind
that the macro recorder isn't perfect. Reply here and post your code
into the message, and we'll see what we can do to clean it up for you.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Melbourne, Australia
 
S

Sam

Thanks very much for your help Shauna

Yes my aim is to make it easy to add a contents page, but
not just for me - it is for anyone who happens to use this
template.

What you told me to do works great for me and it seems to
work on any document I'm in (so long as it has the same
styles).

I would also like to make it available to everyone when in
that template but don't seem to have the option to do this
it just allows me to name it and that's it.

Where do I choose to save it to the template?

Sam
 
S

Suzanne S. Barnhill

When you create the AutoText entry, choose your specific document template
in the "Look in" box at the bottom of the AutoText dialog. Then your entry
will be saved in that template instead of Normal.dot. Be sure to change
"Look in" back to "All active templates" before closing the dialog or you
won't have access to the AT entries in Normal.dot.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
C

Clive Huggan

Sam,

Alluding to your comment "I would also like to make it available to everyone
when in that template", if I take it that people might not know the AutoText
feature for the toc is available in the template, you can make the feature
more accessible to your colleagues by creating a custom toolbar that's
available in that template or documents based on it. (I often create a
special toolbar for a doc/template that has styles etc used in the
particular document/template.)


-- Clive Huggan
 

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