VBA: how to determine in which Table your Cursor is in a Word Document that has several tables

In a Word Document I have several tables. In my Macros I can chose to run some code on one or the other of these tables by referring to the index number of a table with a line like this

I would like to determine in which Table my Cursor is by Running a Macro.
So basically if I run my Macro when my Cursor is in (any Cell of) the Second Table in my Word Document I would like to display a MessageBox showing “2” and if my Cursor is in (any Cell of) the Table 1 I would like to display a MessageBox showing “1” and likewise for any other tables in my Word Document.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

This will return the index number of the table that contains the whole of the Selection. It returns 0 if there is no such table
Sub WhichTable()
    Dim tbl As Table
    Dim t As Integer
    Dim ts As Integer
    For Each tbl In ActiveDocument.Tables
        t = t + 1
        If Selection.Range.InRange(tbl.Range) Then
            ts = t
            Exit For
        End If
    Next tbl
    MsgBox ts
End Sub

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
FaheemAhmadGulAuthor Commented:
Thank you.
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
Microsoft Office

From novice to tech pro — start learning today.