vba - Can excel macro loop through each page of a Word doc to get each table? -


I have a word dock that contains several tables.

I have to export the tables to Excel and also to add the same word page number along with a column next to each line

I want to add my word file to my Excel file I am able to access with. This Excel file will be used to create an index for my Word Dock. I want to loop through each page in the word, then I would like to loop within the page to copy through Excel to each table, in this way I'll know which page I am on my page and get the page number .

So I would like to do something like this:

  Each table on this page copies Excel into Excel and also the word page number at the end of each row  

I have tried to write a macro but it can not get a table within a page:

 set  wdDoc = GetObject ( WdFileName) 'Open Word file with wdDoc pages, with Tot = wdDoc.Pages.Count tableTot = wdDoc.Tables.Count resultRow = 4 tableStart = 1 for tableTot Copy Cell Cells of Excel Cells from the Word Table Cells to the IRO = 1 .Rows.Count iCol = 1 to 2 requires 'First 2 Columns to be copied in Word'. This word page number Does not receive TblPage = .cell (iRow, iCol). Information (3) 'Copy Cells From Excel to Excel Cells (Result, iCol) = Worksheet Function. Clean (.cell (iRow, iCol) .change test) insert the word page number next to the row in the Excel cell (as a result, iCol). Offset (0, 1). Value = TblPage Next iCol results = result rou + 1 next iRow End result with Row = resultRow + 1 next tableStart End with  

However, when I am inside the page loop, Does not appear to reach the page I have tried to use a message box to show the number of tables in that page, but it always shows 0.

Is it possible to access the tables within a page?

Any thank you very much, thanks.

Edit: I have edited the code above and I'm getting closer, only one row with which I'm having trouble is:

  TblPage = .cell (iRow, iCol). Notice (3)  

I is trying to use that line to get the page number from Word, but this is going to be 0 for the page number. Again, I am writing this code in Excel.

Do anyone know the proper way to get the page number from Word?

Thanks again

Your suggested logic is what you need in fact, the best way to loop through the tables And check that which page (end of table) is where you need logic.

GetPageNumberForTable () as TBL table TblPage as integer for each TBL in ActiveDocument.Tables' it requires TblPage = TBL.Range.Information (value) WdActiveEndPageNumber ) 'Test-Check Value' in Instant Window Debug Print TBPs 'Your Copy Code Here' ..... Next End All

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -