Determine position in table

C

Compass Rose

I have a macro that I want to restrict the user from using when the insertion
point is only in column 1 of table 4. I have been using
'Selection.Information(wdWithInTable)' in other macros but is not specific
enough for this application.

What code can I use to accomplish this?

TIA
David
 
J

Jezebel

If Selection.Information(wdWithInTable) then
If Selection.Tables(1).range.start =
activedocument.tables(3).range.start and _
Selection.Cells(1).ColumnIndex = 4 then ...
 
C

Compass Rose

Thanks, Jezebel. I think you've transposed the table number and column
number. Would the correct code not be:

If Selection.Information(wdWithInTable) then
If Selection.Tables(4).range.start =
activedocument.tables(4).range.start and _
Selection.Cells(1).ColumnIndex = 1 then ...

David
 
J

Jezebel

Not quite. If the selection is within a table, then Selection.Tables(1) is a
reference to that table. Selection.Tables(4) would refer to the fourth table
within the selection. You're making two tests --

1. Is the selection within the fourth table in the document --

Selection.Tables(1).range.start = ActiveDocument.Tables(4).Range.Start

2. Is the selection within a given column --

Selection.Cells(1).ColumnIndex = x


Note that this could all get tricky if you have nested tables (ie one table
within another), or if the selection included several tables.
 
C

Compass Rose

Thanks for the explanation.

No, fortunately I don't have nested tables. I try to keep things simple.

David
 

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