> I have several tables nested within a table. How do I find an index of the nested table.
>
What kind of index?
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the
newsgroup and not by e-mail :-)
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"OlgaP" <anon...@discussions.microsoft.com> wrote in message
news:5B520DD8-569C-472D...@microsoft.com...
> I have several tables nested in a table. When user makes selection in one
of the tables, I need to know which table he/she is in.
It doesn't matter how many nested tables there are, if you use
ActiveDocument.Tables.Count, it will only return the number of "un-nested"
tables in the document.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"OlgaP" <anon...@discussions.microsoft.com> wrote in message
news:9CDD0ADF-158C-4962...@microsoft.com...
> Hi Doug! I understand that I can get a reference to the selected table. I
need to know what is the number of this table. If there are 5 nested tables
inside the main table, I need to know what is the number of the table that
the user is in, is it one, two, three, four or five. Thanks for your help.
> I understand that I can get a reference to the selected table. I need to know what is the number of this table. If there are 5 nested tables inside the main table, I need to know what is the number of the table that the user is in, is it one, two, three, four or five.
>
Try it using this:
Selection.Tables(1).NestingLevel
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"Cindy M -WordMVP-" <C.Mei...@hispeed.ch> wrote in message
news:VA.000098a0.005671b3@speedy...
> But if you have two tables nested in different cells of the base table, it
> will not tell you in which one the selection is located. Both of the nested
> tables have a NestingLevel of 2
>
That's not how I understood the original question; I thought the user was
asking for the nesting level. As to getting the "index" of the outermost
table...
You really can't get that information directly, even in non-nested tables, can
you? But this works:
Sub MoveToTopLevelTable()
Dim l As Long
Dim rng As Word.Range
Dim nrTables As Long
Dim rngTables As Word.Range
If Selection.Information(wdWithInTable) Then
l = Selection.Tables(1).NestingLevel
Set rng = Selection.Tables(1).Range
Do While l > 1
rng.Collapse wdCollapseEnd
l = rng.Tables(1).NestingLevel
Set rng = rng.Tables(1).Range
Loop
Set rngTables = ActiveDocument.Range
rngTables.End = rng.End
Debug.Print "The selection is nesting in level " & _
CStr(Selection.Tables(1).NestingLevel) & " in table " _
& rngTables.Tables.Count & " of the document."
End If
End Sub
I guess I am not sure what the OP meant by Index.
While I can think of situations where you might want a table with
NestingLevel of 2, I can't really think of a reasonable use for one nested
deeper than that. I can however think of a situation where you may want
multiple tables with a Nesting Level of 2 in a single table e.g. using a
table to maintain a side by side translation of a document containing
tables.
Here's another method of doing what your macro does:
Dim i As Long, j As Long
If Selection.Information(wdWithInTable) Then
j = Selection.Tables(1).NestingLevel
For i = 1 To ActiveDocument.Tables.Count
If Selection.InRange(ActiveDocument.Tables(i).Range) Then
MsgBox "The selection is in a table with Nesting Level " & j & "
in Table " & i & " in the document."
Exit For
End If
Next i
End If
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"Cindy M -WordMVP-" <C.Mei...@hispeed.ch> wrote in message
news:VA.000098b9.007e0838@speedy...
> I don't need the nesting level, I need to know which table among tables that have nesting level 2 is selected. I am afraid, that Doug is right and I can't find it out.
>
I think both of us have shown you how that works. I know I did in my response to Doug, anyway...