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.

Please see the attached file.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try the following:

Selection.Next(wdparagraph, 1).Select

Open in new window

WonHopAuthor Commented:
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.

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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

WonHopAuthor Commented:
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.
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.
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.
WonHopAuthor Commented:
Sorry for the delay.  I was off on Monday.

    Dim FindRange As Word.Range
    Set FindRange = ActiveDocument.Range
Try the following code:

    Selection.Next(wdParagraph, 1).Select
    If Selection.Information(Word.WdInformation.wdWithInTable) = True Then
        'place your code to obtain information from table here
    End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WonHopAuthor Commented:
This does work.  I will have to add my code to it for the other part.  But you did answer the question that I asked here.

Thank you very much.

Like I said the the other question, please stand by.  I am sure I will be back.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.