eed
02-09-2006, 02:44 PM
Hi, all,
Let me see if I can explain this clearly. I want my code to create a Table of Contents including all items in a style I've defined, SectionTitle, but I do NOT want the TOC to include any of the standard header styles. It works correctly when I do it manually, but I can't seem to make this work correctly from code.
In my Word document, I manually created a TOC including Header 1 and my SectionTitle style. Then I manually created a TOC excluding Header 1 and including only my SectionTitle style. I used the Macro Recorder to trap and compare the code:
' TOC includes Header1 AND SectionTitle styles
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=1, IncludePageNumbers:=True, AddedStyles:= _
"SectionTitle,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
' TOC includes ONLY SectionTitle styles
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=False, IncludePageNumbers:=True, AddedStyles _
:="SectionTitle,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
I tried using the second piece of code (I'm working from Access VBA), but the resulting TOC still includes text formatted with the Header1 style as well as the SectionText style. I can't determine what Word is interpreting during manual creation that I'm not managing to tell it during automated creation.
I'd appreciate any insights. Please let me know if I haven't explained my problem clearly enough.
Thanks!!!
~eed
Let me see if I can explain this clearly. I want my code to create a Table of Contents including all items in a style I've defined, SectionTitle, but I do NOT want the TOC to include any of the standard header styles. It works correctly when I do it manually, but I can't seem to make this work correctly from code.
In my Word document, I manually created a TOC including Header 1 and my SectionTitle style. Then I manually created a TOC excluding Header 1 and including only my SectionTitle style. I used the Macro Recorder to trap and compare the code:
' TOC includes Header1 AND SectionTitle styles
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=1, IncludePageNumbers:=True, AddedStyles:= _
"SectionTitle,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
' TOC includes ONLY SectionTitle styles
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=False, IncludePageNumbers:=True, AddedStyles _
:="SectionTitle,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
I tried using the second piece of code (I'm working from Access VBA), but the resulting TOC still includes text formatted with the Header1 style as well as the SectionText style. I can't determine what Word is interpreting during manual creation that I'm not managing to tell it during automated creation.
I'd appreciate any insights. Please let me know if I haven't explained my problem clearly enough.
Thanks!!!
~eed