I have a long word document with over 100 tables. I am trying to allow users to select a page number via python to enter data into the table on the specified page within the word document. I am able to enter data into a table with the following code, but the problem is that the document is so long, it's not easy for a user to know which table number they are on when they are 80 pages into the word document (not every page has a table and some pages have multiple tables).
import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Documents.Open(my_document_path)
doc = word.ActiveDocument
table = doc.Tables(51) #random selection for testing purposes
table.Cell(Row = 7, Column = 2).Range.Text = "test"
So what I need help with is extracting the table number on a page in a word document that is specified via user input (i.e., user specifies that they want to add data to page 13 so the code will determine that table 51 is on page 72).
If I record a macro in word for simply jumping to a page, this is the VB code...
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="13"
I have tried translating this into Python using the following line of code, but it's not jumping to the correct page.
doc.GoTo(win32.constants.wdGoToPage, win32.constants.wdGoToNext, "13")