The HeadingStyles object provides a way to add and delete custom
styles as table of contents entries (corresponding to the list after
the \t switch in the TOC field). To control which built-in heading
styles (or custom styles with an outline level defined in their
Paragraph formats) are used, you need the UseHeadingStyles property
and UpperHeadingLevel and LowerHeadingLevel properties. Read Word VBA
help for more.
The following is a very basic example which adds some custom styles to
be used in the TOC. (Note that the macro does not run if there isn't
already a TOC in the document. Also note that I haven't included a
test to see if the style names actually exist in the document.)
Sub main()
Dim tt As TablesOfContents
Dim h As HeadingStyle
Set tt = ActiveDocument.TablesOfContents
With tt
If .Count > 0 Then
While .Item(1).HeadingStyles.Count > 0
.Item(1).HeadingStyles(1).Delete
Wend
.Item(1).HeadingStyles.Add "test style 1", 1
.Item(1).HeadingStyles.Add "test style 2", 2
.Item(1).HeadingStyles.Add "test style 3", 3
.Item(1).HeadingStyles.Add "test style 4", 1
tt(1).Update
End If
End With
End Sub
Note that it might be easier to work directly with the TOC
field (accessible via a Fields collection).