HeadingStyles Collection Object

Microsoft Word Visual Basic

Multiple objectsHeadingStyles
HeadingStyle

A collection of HeadingStyle objects that represent the styles used to compile a table of figures or table of contents.

Using the HeadingStyles Collection

Use the HeadingStyles property to return the HeadingStyles collection. The following example displays the number of items in the HeadingStyles collection for the first table of contents in the active document.

MsgBox ActiveDocument.TablesOfContents(1).HeadingStyles.Count
		

Use the Add method to add a style to the HeadingStyles collection. The following example adds a table of contents at the beginning of the active document and then adds the Title style to the list of styles used to build a table of contents.

Set myToc = ActiveDocument.TablesOfContents.Add _
    (Range:=ActiveDocument.Range(0, 0), UseHeadingStyles:=True, _
     LowerHeadingLevel:=3, UpperHeadingLevel:=1)
myToc.HeadingStyles.Add Style:="Title", Level:=2
		

Use HeadingStyles(index), where index is the index number, to return a single HeadingStyle object. The index number represents the position of the style in the HeadingStyles collection. The following example adds (at the beginning of the active document) a table of figures built from the Title style, and then displays the name of the first style in the HeadingStyles collection.

Set myTOF = ActiveDocument.TablesOfFigures.Add _
    (Range:=ActiveDocument.Range(0, 0), AddedStyles:="Title")
MsgBox myTOF.HeadingStyles(1).Style