Determine Table Index Number in a Table Collection

A

Andrew

Simple problem I would think. In a document with multiple tables, how do I determine the index number of the table in which the cursor is located. I want to write this cod

ActiveDocument.Tables(???

How do I know if my current location is Tables(1), Tables(2) or Tables(3

Thank you
Andrew
 
J

Jay Freedman

Hi Andrew

See http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm.

Pay special attention to the first part, which explains that you
usually don't need to know the absolute index of anything within the
document.

Something it doesn't say is that if you frequently refer to objects by
their absolute index, your macro is likely to run extremely slowly in
large documents. The reason is that every time you say something like
ActiveDocument.Tables(n), VBA starts with .Tables(1) and counts tables
up to n. If n is 100 or so, you'll bring the machine to its figurative
knees -- and it's totally unnecessary!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top