Share via

Issue while adding/updating TOC in MS Word using OpenXML

Anonymous
2021-02-12T07:48:13+00:00

I have a requirement to add/update TOC - Table of Contents in MS document using OpenXML. I am facing challenges to achieve the same. I am using MS Office 2016.

I have tried all the options from this post: How to generate Table Of Contents using OpenXML SDK 2.0?

Also gone through Eric White videos.

I am trying to use UpdateField option and able to add empty TOC following the sample code from the above link.

However, when I open the document I am not getting a pop-up dialog which will ask to update the TOC.

Please let me know what is the best option to create/update TOC through code.

Why there is not much documentation on TOC as it is very important part?

Your answer/comment is really very helpful.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Charles Kenyon 167.3K Reputation points Volunteer Moderator
    2021-02-12T20:09:14+00:00

    ***

    So, I am sure it is not about Headings rather than UpdateField as it is not showing dialog box while opening the document. ***

    While you may be sure, I am not. You certainly may be correct. My suggestion to open in Word and insert a TOC was intended as a diagnostic, not a method to complete your task.

    Is this a homework assignment?

    In your cross-post, I suggested posting a sample document with the problem. You can do that here if you want.

    Trouble Shooting - Share OneDrive File - by Rohn

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Charles Kenyon 167.3K Reputation points Volunteer Moderator
    2021-02-12T08:23:55+00:00

    What happens if you try inserting a TOC using Word, itself, rather than through OpenXML?

    I suspect that your headings may not be headings that :Word recognizes as such.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2021-02-12T09:41:33+00:00

    Hi Charles,

    Thanks for your response and the links you provided.

    Well creating TOC through OpenXML is the requirement.

    I can see heading properly in Navigation Panel and using Macro I am able to create TOC with the same. So, I am sure it is not about Headings rather than UpdateField as it is not showing dialog box while opening the document.

    Do  you have any idea why UpdateField is not working? 

    Thanks

    Mateen

    Was this answer helpful?

    0 comments No comments
  4. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2021-02-12T08:28:35+00:00

    Was this answer helpful?

    0 comments No comments