C
Chuck
I've got a sub that allows users to insert a new Table of Contents (TOC) anywhere in a document. There may be no existing TOCs or more than one.
How should the code refer to the TOC that the sub inserts? How can I determine the index number of the TOC that my code inserts when there may be any number of existing TOCs?
For example, say there are two existing TOCs in the current document, TOC(1) and TOC(2). The user wants to insert a new TOC between TOC(1) and TOC(2). I'm assuming that the code cannot specify "ActiveDocument.TableOfContents(2)" because the code has to allow for situations where the new TOC will be inserted before TOC(1) or after TOC(2), or after TOC(5) for that matter.
Using the sample code below, what number/variable would I replace "???" with?
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="Level1,1,Level2,2" 'style names examples only
.TablesOfContents(???).TabLeader = wdTabLeaderDots
End With
Hope this question is clear, and thanks for any help!
How should the code refer to the TOC that the sub inserts? How can I determine the index number of the TOC that my code inserts when there may be any number of existing TOCs?
For example, say there are two existing TOCs in the current document, TOC(1) and TOC(2). The user wants to insert a new TOC between TOC(1) and TOC(2). I'm assuming that the code cannot specify "ActiveDocument.TableOfContents(2)" because the code has to allow for situations where the new TOC will be inserted before TOC(1) or after TOC(2), or after TOC(5) for that matter.
Using the sample code below, what number/variable would I replace "???" with?
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="Level1,1,Level2,2" 'style names examples only
.TablesOfContents(???).TabLeader = wdTabLeaderDots
End With
Hope this question is clear, and thanks for any help!