A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to find the index number of the table if it is a nested table.



 
 
Thread Tools Display Modes
  #1  
Old May 19th, 2004, 06:31 PM
OlgaP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

I have several tables nested within a table. How do I find an index of the nested table.
  #2  
Old May 20th, 2004, 04:17 PM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Hi =?Utf-8?B?T2xnYVA=?=,

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 :-)

  #3  
Old May 20th, 2004, 04:26 PM
OlgaP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

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.
  #4  
Old May 21st, 2004, 07:38 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Can you get by with Selection.Tables(1) That will give a reference to the
table in which the selection is located.

--
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" wrote in message
...
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.

  #5  
Old May 21st, 2004, 03:41 PM
OlgaP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

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.
  #6  
Old May 21st, 2004, 11:17 PM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Based on my attempts, I don't think that you can.

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" wrote in message
...
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.

  #7  
Old May 22nd, 2004, 10:41 AM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Hi =?Utf-8?B?T2xnYVA=?=,

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

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 :-)

  #8  
Old May 22nd, 2004, 01:33 PM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

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

--
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-" wrote in message
news:VA.000098a0.005671b3@speedy...
Hi =?Utf-8?B?T2xnYVA=?=,

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

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 :-)


  #9  
Old May 23rd, 2004, 09:54 AM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Hi Doug,

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


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 :-)

  #10  
Old May 23rd, 2004, 10:59 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default How to find the index number of the table if it is a nested table.

Hi Cindy,

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-" wrote in message
news:VA.000098b9.007e0838@speedy...
Hi Doug,

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


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 :-)


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.