Search code examples
c#ms-wordoffice-interoptableofcontents

Microsoft.Office.Interop.Word with C# - Identify Existing Table of Contents Object


I'm working off a template document that has an existing Table of Contents object. I am having trouble identifying it and assigning it to a TableOfContents object programatically for further manipulation/updating.

I have examined the documentation for the TablesOfContents interface, and the only way I can see to return an object of the proper type is through the TablesOfContents.Add() function. I don't want to add a new TOC though. I just want to identify the one that already exists.


Solution

  • This seems to be explained in the documentation:

    "The Document.TablesOfContents Property returns a TablesOfContents collection that represents the tables of contents in the specified document."

    Once you have that, "Use TablesOfContents(index), where index is the index number, to return a single TableOfContents object. The index number represents the position of the table of contents in the document."