How do I get a list of all the headings in a word document by using VBA?
The easiest way to get a list of headings, is to loop through the paragraphs in the document, for example:
Sub ReadPara()
Dim DocPara As Paragraph
For Each DocPara In ActiveDocument.Paragraphs
If Left(DocPara.Range.Style, Len("Heading")) = "Heading" Then
Debug.Print DocPara.Range.Text
End If
Next
End Sub
By the way, I find it is a good idea to remove the final character of the paragraph range. Otherwise, if you send the string to a message box or a document, Word displays an extra control character. For example:
Left(DocPara.Range.Text, len(DocPara.Range.Text)-1)