Tom
Tom

Reputation: 6707

how to create Table-of-contents (TOC) via macro

I need to create table - of-contents after mailmerge by macro as word does not support updating TOC field from TC fields.

Is it possible to automate creating TOC ?

Upvotes: 2

Views: 7670

Answers (1)

DAC
DAC

Reputation: 1809

This will create a TOC using VBA:

    Set rangeWord = ActiveDocument.Range(Start:=0, End:=0)
    ActiveDocument.TablesOfContents.Add rangeWord, _
                                    UseFields:=True, _
                                    UseHeadingStyles:=True, _
                                    LowerHeadingLevel:=3, _
                                    UpperHeadingLevel:=1

Upvotes: 4

Related Questions