"Table of Contents Options"

G

Guest

Hi,

can anybody please tell me which object holds the information from the
"Table of Contents Options" dialogue? Specifically I'm after the bindings
between styles and TOC levels.

Many thanks in advance,

Rad
 
C

Charles Kenyon

These are field switches. The Table of Contents is a field.
http://sbarnhill.mvps.org/WordFAQs/TOCTips.htm
http://word.mvps.org/FAQs/Formatting/TOCSwitches.htm
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

Stefan Blom

The HeadingStyles object provides a way to add and delete custom
styles as table of contents entries (corresponding to the list after
the \t switch in the TOC field). To control which built-in heading
styles (or custom styles with an outline level defined in their
Paragraph formats) are used, you need the UseHeadingStyles property
and UpperHeadingLevel and LowerHeadingLevel properties. Read Word VBA
help for more.

The following is a very basic example which adds some custom styles to
be used in the TOC. (Note that the macro does not run if there isn't
already a TOC in the document. Also note that I haven't included a
test to see if the style names actually exist in the document.)

Sub main()
Dim tt As TablesOfContents
Dim h As HeadingStyle

Set tt = ActiveDocument.TablesOfContents

With tt
If .Count > 0 Then
While .Item(1).HeadingStyles.Count > 0
.Item(1).HeadingStyles(1).Delete
Wend
.Item(1).HeadingStyles.Add "test style 1", 1
.Item(1).HeadingStyles.Add "test style 2", 2
.Item(1).HeadingStyles.Add "test style 3", 3
.Item(1).HeadingStyles.Add "test style 4", 1
tt(1).Update
End If
End With


End Sub

Note that it might be easier to work directly with the TOC
field (accessible via a Fields collection).
 

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