C
Chuck
A general question about how to refer to a specific TOC (table of contents) in a document:
If a sub adds a TOC to a document that may already have one or more than one TOC, is there an easy way to either determine that TOC's index or assign it a tag of some sort? We have documents that can contain any multiple (different) TOCs in anywhere in the document.
For example, if the user may need to insert a TOC ("NEW-TOC") after TOC(1) but before current TOC(2). For the purposes of working with NEW-TOC, what value/variable goes in the index position in the following line, bearing in mind that the code has to accommodate adding a TOC anywhere in a document where the number of TOCs isn't known ahead of time:
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, _
RightAlignPageNumbers:= True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="Level 1,1,Level 2,2" 'style names as examples only
.TablesOfContents(NEW-TOC).TabLeader = wdTabLeaderDots
End With
I know I can't specify "2" in place of "NEW-TOC" in the above sample code, because the code also has to work if the user is inserting the TOC after current TOC(2) or before current TOC(1). The user picks the insertion point for NEW-TOC as needed.
I hope this question is clear and appreciate any assitance. Thanks!
If a sub adds a TOC to a document that may already have one or more than one TOC, is there an easy way to either determine that TOC's index or assign it a tag of some sort? We have documents that can contain any multiple (different) TOCs in anywhere in the document.
For example, if the user may need to insert a TOC ("NEW-TOC") after TOC(1) but before current TOC(2). For the purposes of working with NEW-TOC, what value/variable goes in the index position in the following line, bearing in mind that the code has to accommodate adding a TOC anywhere in a document where the number of TOCs isn't known ahead of time:
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, _
RightAlignPageNumbers:= True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="Level 1,1,Level 2,2" 'style names as examples only
.TablesOfContents(NEW-TOC).TabLeader = wdTabLeaderDots
End With
I know I can't specify "2" in place of "NEW-TOC" in the above sample code, because the code also has to work if the user is inserting the TOC after current TOC(2) or before current TOC(1). The user picks the insertion point for NEW-TOC as needed.
I hope this question is clear and appreciate any assitance. Thanks!