Apply a paragraph style to a Table of Contents

A

Alex St-Pierre

Hi!
I would like to apply "TOC1" paragraph style to a table of content (item
"Heading Section;1"). I tried the following but doesn't work. Any idea?
Thank you!
Alex
docWord.Paragraphs(iTOC).Styles = "TOC1"
docWord.TablesOfContents.Add Range:=docWord.Paragraphs(iTOC).Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=False, IncludePageNumbers:=True,
AddedStyles _
:="Heading Section;1", UseHyperlinks:=True, HidePageNumbersInWeb _
:=True, UseOutlineLevels:=False
docWord.TablesOfContents(1).TabLeader = wdTabLeaderDots
docWord.TablesOfContents.Format = wdIndexIndent
 
S

Stefan Blom

If "Heading Section" is the name of a style, you will have to assign
it to TOC level 1; then each paragraph using this style will display
as a level 1 entry in the table of contents. The easiest way to do
this is to modify the field code of the TOC field. In other words, you
would need something like this:

f.Code.Text = "TOC \o \t ""Heading Section;1;my custom style;2"" \h"

(assuming of course that f is a valid reference to a Field object).

Note that if your list separator (Regional Optins in Control Panel) is
a comma, that's what you should be using in the field code above
(instead of a semi-colon).

If there is just one TOC field (corresponding to a single TOC), you
could easily locate the field in a loop:

For Each f In ActiveDocument.Fields
If f.Type = 13 Then
'Set the Text property as indicated above...
End If
Next f

Then update the TOC:

ActiveDocument.TablesOfContents(1).Update

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 

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