Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Apply a paragraph style to a Table of Contents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex St-Pierre - 17 Dec 2006 14:18 GMT
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
Signature

Alex St-Pierre

Stefan Blom - 19 Dec 2006 10:06 GMT
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

Signature

Stefan Blom
Microsoft Word MVP

> Hi!
> I would like to apply "TOC1" paragraph style to a table of content (item
[quoted text clipped - 10 lines]
>    docWord.TablesOfContents(1).TabLeader = wdTabLeaderDots
>    docWord.TablesOfContents.Format = wdIndexIndent

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.