-
-
Save garymanley/2a4e6530c5624dfcc8a8a44552df4487 to your computer and use it in GitHub Desktop.
Update word document contents page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
def update_toc(docx_file): | |
word = win32com.client.DispatchEx("Word.Application") | |
doc = word.Documents.Open(docx_file) | |
doc.TablesOfContents(1).Update() | |
doc.Close(SaveChanges=True) | |
word.Quit() | |
### End python docx as follows | |
#filenamedocx = r'C:\Users\garym\Documents\New folder (2)\Running_report'+datetime.datetime.today().strftime('%d%m%y')+'.docx' | |
#document.save(filenamedocx) | |
## Then run the update contents page function | |
update_toc(filenamedocx) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment