-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
Hi,
I am adding new content to an existing Word document and I want an approach to auto-refresh my document's Table of contents. I've used below code but it is not showing any result and the document created out of it is struck in background process for which i had to kill from task manager.
import win32com.client
def update_toc(docx_file):
word = win32com.client.DispatchEx("Word.Application")
doc = word.Documents.Open(docx_file)
toc_count = doc.TablesOfContents.Count
if toc_count == 1:
toc = doc.TablesOfContents(1)
toc.Update()
print('TOC should have been updated.')
else:
print('TOC has not been updated for sure...')
update_toc(r"C:\Users\Mydocument.docx")
Will someone help me with the details to auto refresh my word document?
damies13 and USSX-Hares
Metadata
Metadata
Assignees
Labels
No labels