PDA

View Full Version : Using Excel VBA Get the "Page Number" of Table current cells in Winword.



justuptou
01-08-2020, 10:33 PM
Dear all,

I am using the Excel Table to store some records,
then using VBA copy the a lot of data to winword table and generate the report.
( see attached )25774

My Pseudo code by Excel VBA coding :
Copy Excel to Data Array
Open Winword.application
Create a table in winword
then Put the Data Array into the winword
(I want to do something when there is different page)
(so, How can I coding when I copy data to winword that I know the page number ( for example there is in Page 1 or 2 ))
Rename and Saved the file
Close Winword.application

I have tried to set the value / show it in msgbox as below coding.
MsgBox objDoc.tables(1).Cell(1, 1).Range.Information(wdActiveEndPageNumber) or
A = objDoc.tables(1).Cell(1, 1).Range.Information(wdActiveEndPageNumber)
' Report the existing cell (try the First cell) which page is located but failed as 'Run-time error 4608 / Value out of range'
25775

Dave
01-09-2020, 07:41 AM
You haven't indicated if U are using early or late binding. If U are using late binding then U must use the Word constant for page. So...

objDoc.tables(1).Cell(1, 1).Range.Select
MsgBox objDoc.Selection.Information(3)
HTH. Dave

justuptou
01-09-2020, 06:39 PM
Thanks Dave, I have just tried your coding as below,

Coding
Msgbox objDoc.tables(1).Cell(1, 1).Range.Text ( << Result is good : shown S-00001 )

objDoc.tables(1).Cell(1, 1).Range.Select
MsgBox objDoc.Selection.Information(wdActiveEndPageNumber) or
MsgBox objDoc.Selection.Information(3) or

https://wellsr.com/vba/assets/images/2016-09-24-outlook-runtime-error-438-application-filedialog.png


You haven't indicated if U are using early or late binding. If U are using late binding then U must use the Word constant for page. So...

objDoc.tables(1).Cell(1, 1).Range.Select
MsgBox objDoc.Selection.Information(3)
HTH. Dave