MS Word - Identify the Table Below Text That Is Found.
This is question 2 of 3 that I am asking. Microsoft Word 2016 VBA. I am using fake data because I can't put company data out here.
I have code that finds the words that I need. I will do a search and find "TABLE C-1"
When it finds "TABLE C-1", I need to identify the Table directly below the Text. Once it is identified, I need to set focus/put the cursor in the first cell so that I can get all of the data from the table. I have found code that will go thru the table can get the data.
Hello. irudyk. Thanks for your response. How do I get the Table index number so that I can reference it and go to the first cell in the table?
BTW. I have to leave for the day and I will be back on Tuesday to check for any other responses. Have a great weekend.
Thanks
WonHop
irudyk
The above code will put you in the first cell of the table.
If you then define your table variable as for example varTable = Selection.Tables(1), you can then parse each cell in the varTable.
I suppose if you really need to know it's index value you could set a variable to = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
Hello irudyk. My question 2 and 3 are getting the same 5981 error message. I have attached a photo of the error message.
This is the code I tried.
strTableIndex = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
The thing is, there could be over 40 table in the document that is over 125 pages. That is why I need to be able to identify that particular table so that I get the correct data from the correct table. Error_Message.JPG
irudyk
I see what you are saying but, the code I provided you puts you in the table you want to be in.
So if you set a variable when you are in the table as varTable = Selection.Tables(1) (I previously stated incorrectly that it was Selection.Table(1)) you can then parse varTable for each cell.
I'd have to look into the error you are getting, but if you use the above, it is a moot point.
irudyk
The error is likely related to what’s happening in your 3rd question and is related to how your FindRange object is defined. Providing that information would be very useful.
Open in new window