Getting the headings from a Word document

后端 未结 7 1098
挽巷
挽巷 2020-11-30 04:11

How do I get a list of all the headings in a word document by using VBA?

相关标签:
7条回答
  • 2020-11-30 04:56

    Why reinventing the wheel so many times?!?

    A "list of all headings" is just the standard Word index of document!

    This is what I got by recording a macro while adding index to the document:

    Sub Macro1()
        ActiveDocument.TablesOfContents.Add Range:=Selection.Range, _
            RightAlignPageNumbers:=True, _
            UseHeadingStyles:=True, _
            UpperHeadingLevel:=1, _
            LowerHeadingLevel:=5, _
            IncludePageNumbers:=True, _
            AddedStyles:="", _
            UseHyperlinks:=True, _
            HidePageNumbersInWeb:=True, _
            UseOutlineLevels:=True
    End Sub
    
    0 讨论(0)
提交回复
热议问题