TOC is picking up extra styles

V

Vivian Carroll

In Word 2002, I recorded the following code to insert a TOC. Note that it is
only supposed to pick up four styles "C-Heading 1, C-Heading 2, C-Heading 3,
and C-Table Step 2."

The problem is that it is also picking up styles "C-Heading 4" and "C-Table
Step 3."

All of the "C-Heading" styles are based on to C-Heading 1 as part of an
outline numbering scheme. The "C-Table" styles are based on the C-Heading
styles of the same number and are then modified (for example, C-Table Step 3
is based on C-Heading 3).

How can I modify the code to prevent it from picking up C-Heading 4 and
C-Table Step 3 in the TOC?

With ActiveDocument
.TablesOfContents.Add _
Range:=Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="C-Heading 1,1,C-Heading 2,2,C-Heading 3,3,C-Table
Step 2,2", _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderSpaces
.TablesOfContents.Format = wdIndexIndent
End With

TIA, Vivian
 
C

Chad DeMeyer

Vivian,

How about something like this:

ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:="TOC \t "C-Heading 1,1,C-Heading 2,2,C-Table Step 2,2, C-Heading
3,3 \z \h"

Regards,
Chad
 
C

Chad DeMeyer

I noticed some errors with regards to quotation marks when reading my
original post:

ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:="TOC \t ""C-Heading 1,1,C-Heading 2,2,C-Table Step 2,2, C-Heading
3,3"" \z \h"

Regards,
Chad
 
V

Vivian Carroll

Thanks Chad,

That did half of the job - it stopped it from picking up C-Heading 4.
However, it is still picking up the level 3 heading called C-Table Step 3
that I don't want. Is there any way to stop that or does the TOC always pick
up all styles at the outline levels that you specify to show (3 in my case)?

What do the \t, \z and \h switches do?

Vivian
 
C

Chad DeMeyer

Vivian,

\t always followed by a string argument, which lists specific styles to
includes in the TOC and what level to include them at
e.g., "Title,1,Subtitle,2"
\z Hide page numbers in web layout
\h Use hyperlinks

\o Include all styles which are defined as being in the outline levels
specified by the argument - so yes, \o "1-3" will cause C-Table Step 3 to be
picked up in the TOC, because (I assume) that style is marked as outline
Level 3 in its style definition. I almost never use the \o switch - I
prefer to explicitly list a few styles with the \t switch.

Hope that helps
Regards,
Chad
 
V

Vivian Carroll

Thanks for the switch descriptions, Chad.

However, you say why not to use \o and you didn't use \o in the code you
gave me - but it is still picking up C-Table Step 3 (which is marked as
outline Level 3) even though you/I didn't use the \o switch. So what can I
do to say "don't include C-Table Step 3"?

Vivian
 
C

Chad DeMeyer

Vivian,

Sorry, that's a head scratcher. If you want to send me the document, I can
play around with it and see if I can figure it out?

Regards,
Chad
 

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

Similar Threads

Table of Contents Nightmare 1
Table of Contents Styles font issue 5
Table of Content 1
TOC problem 0
TOC Help 0
TOC Problem 0
TOC Question 3
Apply a paragraph style to a Table of Contents 1

Top