Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-30-2016, 10:24 AM
amer1749 amer1749 is offline Code to creating a custom TOC including too many styles Windows 7 64bit Code to creating a custom TOC including too many styles Office 2013
Novice
Code to creating a custom TOC including too many styles
 
Join Date: Jun 2016
Posts: 5
amer1749 is on a distinguished road
Default Code to creating a custom TOC including too many styles

I'm trying to write code to insert a custom table of contents. The code first writes "Table of Contents" in a new paragraph and sets that paragraph to a style other than Heading 1 or Heading 2 (though it is based on Heading 1).

Then I try this:

Code:
With ActiveDocument
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
            True, UseHeadingStyles:=False, IncludePageNumbers:=True, AddedStyles _
            :="Heading 1,Heading 2", UseHyperlinks:=True, _
            HidePageNumbersInWeb:=True, UseOutlineLevels:=False
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
        .TablesOfContents.Format = wdIndexIndent
End With
Despite code specifying exactly what styles to use, the resulting TOC uses Doc Title, all nine Heading N styles, and the custom TOC style -- which results in the TOC displaying an entry for itself, which is just stupid.



What am I missing?

(FWIW, if I turn on the macro recorder and insert a TOC that correctly excludes the TOC style, I get exactly what I want, and I get almost exactly the code above. The only difference is that the recorder writes
Code:
AddedStyles:="Heading 1, 1, Heading 2, 2"
. The MSDN reference for the TableOfContents.Add method does not show the levels, just a comma-delimited list of styles to include. Doesn't matter; the code fails the same way.)
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to creating a custom TOC including too many styles How to create custom table styles? Pey1 PowerPoint 1 05-25-2016 02:15 AM
Styles in a Custom Ribbon inagalaxyfarfarawry Word 5 12-15-2015 11:18 AM
Custom Bar Styles dbsoccer Project 7 10-31-2013 07:26 AM
creating new styles hannu Word 8 04-28-2013 11:23 PM
Code to creating a custom TOC including too many styles Creating Styles Template? Stone Word 2 09-11-2012 04:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft