Class HeadingStyle (Word VBA)

The class HeadingStyle represents a style used to build a table of contents or figures. The HeadingStyle object is a member of the HeadingStyles collection.

Set

To use a HeadingStyle class variable it first needs to be instantiated, for example

Dim hse as HeadingStyle
Set hse = ActiveDocument.TablesOfFigures(1).HeadingStyles(Index:=1)

The following procedures can be used to set variables of type HeadingStyle: HeadingStyles.Add, HeadingStyles.Item, TableOfContents.HeadingStyles and TableOfFigures.HeadingStyles

For Each

Here is an example of processing the HeadingStyle items in a collection.

Dim hse As HeadingStyle
For Each hse In ActiveDocument.TablesOfFigures(1).HeadingStyles
	
Next hse

Delete

Deletes the specified heading style.

ActiveDocument.TablesOfFigures(1).HeadingStyles(1).Delete

Level

Returns or sets the level for the heading style in a table of contents or table of figures.

ActiveDocument.TablesOfContents.Add _ 
 Range:=Selection.Range, _ 
 RightAlignPageNumbers:=True, _ 
 UseHeadingStyles:=True, _ 
 UpperHeadingLevel:=1, _ 
 LowerHeadingLevel:=3, _ 
 IncludePageNumbers:=True, _ 
 TableID:=wdTOCFormal 
With ActiveDocument.TablesOfContents(1).HeadingStyles 
 .Add Style:="Title", Level:=1 
 .Add Style:="SubTitle", Level:=2 
 .Add Style:="List Bullet", Level:=3 
End With 
With ActiveDocument.TablesOfContents(1) 
 .HeadingStyles(1).Level = 2 
 .HeadingStyles(2).Level = 4 
 .HeadingStyles(3).Level = 6 
End With

Parent

Returns an object that represents the parent object of the specified HeadingStyle object.

Dim objParent As Object
Set objParent = ActiveDocument.TablesOfFigures(1).HeadingStyles(1).Parent

Style

Returns or sets the style for a heading. Read/write Variant.

To set this property, specify the local name of the style, an integer, a WdBuiltinStyle constant, or an object that represents the style.

ActiveDocument.TablesOfFigures(1).HeadingStyles(1).Style =

HeadingStyles.Add

Returns a HeadingStyle object that represents a new heading style added to a document. The new heading style will be included whenever you compile a table of contents or table of figures.

Syntax : expression.Add (Style, Level)

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

Arguments

The following arguments are required:

Style (Style) - The style you want to add. You can specify this argument by using either the string name for the style or a Style object.

Level (Integer) - A number that represents the level of the heading.

HeadingStyles.Count

Returns a Long that represents the number of heading styles in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.TablesOfFigures(1).HeadingStyles.Count

HeadingStyles.Item

Returns an individual HeadingStyle object in a collection.

Syntax : expression.Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position of the individual object.

Dim hse As HeadingStyle
Set hse = ActiveDocument.TablesOfFigures(1).HeadingStyles(Index:=1)

HeadingStyles.Parent

Returns an object that represents the parent object of the specified HeadingStyles object.

Dim objParent As Object
Set objParent = ActiveDocument.TablesOfFigures(1).HeadingStyles.Parent