In my Word document I have multiple tables which are in different pages. I need to import the table inside Excel which has already been done with the sample code I have found from Macro to export MS Word tables to Excel sheets .
However I intend to import the page number of the table (in Word) into Excel and set it as the Sheet Name but I am unable to find anything at all in the Internet after hours of searching.
How do I import the page number of the table in Word into Excel?
I know that to set it as the Sheet Name we use the command
Activesheet.Name="insert_page_number"
but how do we import the page number of the table that we imported from Word into Excel?
You can read the page number using Range.Information(wdActiveEndPageNumber)
. In the sample that you link to, this would look as follows:
Dim pageNumber as Integer
Dim wdRange as Range
With .tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
For iCol = 1 To .Columns.Count
Cells(iRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
Next iRow
' get the page number of the first paragraph in the table
pageNumber = .Range.Paragraphs(1).Range.Information(wdActiveEndPageNumber)
' write the page number below the table
Cells(iRow + 1, 1) = "Page " & pageNumber
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.