locked
How to extract nested TOC content RRS feed

  • Question

  • Hi ,

    I have a document where TOC has nested TOC(TOC within TOC). And at every operation on document I will do ActiveDocument.Fields.Update(). But It is updating only the outer TOC part. This code is not reaching to nested TOC. so to update nested TOC fields i need to extract nested TOC. Can any one suggest me how to extract nested TOC content.

    Thanks,

    Gayatri

    Monday, August 28, 2017 12:26 PM

All replies

  • Hi GayatriK,

    you can try to create object of particular toc and try to loop through its fields.

    something like below.

     Word.Document document = this.Application.ActiveDocument;
    
      Word.TableOfContents oneToC = document.TablesOfContents[1];
                oneToC.Range.Select();
                foreach (Word.Field f in document.Fields)
                {
                    if (f.Type == Word.WdFieldType.wdFieldTOC)
                    {
                        f.Select();
                        MessageBox.Show( f.ToString());
                        break;
                    }
                }

    Reference:

    TablesOfContents Object (Word)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 29, 2017 9:10 AM