Question

In MS Word, table of contents (TOC) can be converted to normal text manually using Ctrl-Shift-F9.

Is there a way to convert TOC to normal text programatically?

Word VBA has TableOfContents class but, it seems, the class doesn't provide any method that can be used for such conversion.

Was it helpful?

Solution

Well, it is not that hard. Here is the solution:

For Each nextTOC In ActiveDocument.TablesOfContents
    nextTOC.Range.Fields.Unlink
Next

In the snippet above, the code loops through all the tables of contents in the active document, gets Fields property of each TOC's Range and calls Unlink on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top