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  

Nested Tables



 
 
Thread Tools Display Modes
  #1  
Old November 18th, 2009, 10:11 AM posted to microsoft.public.word.tables
Ward
external usenet poster
 
Posts: 28
Default Nested Tables

Hi,
I work in VBA with nested tables. After nested table (a child- or sub-table)
is selected i do some table formatting to both nested table and parent table.
So in my code i want to Set tblParent to the parent table. But i have no idea
how to address the parent table directly. I know that i can move the range by
counting cells like:

Dim tblParent As Table, tblSelection As Table
Dim rng As Range

' with help of the used table.style name i checked if the Child table is
selected if so:
Set tblSelection = Selection.Range.Tables(1)
Set rng = tblSelection.Cell(1, 1).Range
rng.MoveEnd Unit:=wdCell, Count:=-1
Set tblParent = rng.Tables(1)

But I prefer to address the ParentTable direct. Do you have an idea how?

Thanks,
Ward
  #2  
Old November 18th, 2009, 01:16 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Nested Tables

I am not sure whether you will find the following better:

Dim tblParent As Table
Dim nIndex As Long

If Selection.Tables(1).NestingLevel 1 Then 'nested
'Find the index of the first character before the nested table
'that character is in the parent table
nIndex = Selection.Tables(1).Range.Start
Set tblParent = ActiveDocument.Range.Tables(ActiveDocument.Range(0 ,
nIndex).Tables.Count)
End If

I have tested a little. If you have more nesting levels, the code still
selects the first-level table. I am on my way out just now, so I am not able
to experiment further now. Please post back if needed and I will take a look
later.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ward" wrote:

Hi,
I work in VBA with nested tables. After nested table (a child- or sub-table)
is selected i do some table formatting to both nested table and parent table.
So in my code i want to Set tblParent to the parent table. But i have no idea
how to address the parent table directly. I know that i can move the range by
counting cells like:

Dim tblParent As Table, tblSelection As Table
Dim rng As Range

' with help of the used table.style name i checked if the Child table is
selected if so:
Set tblSelection = Selection.Range.Tables(1)
Set rng = tblSelection.Cell(1, 1).Range
rng.MoveEnd Unit:=wdCell, Count:=-1
Set tblParent = rng.Tables(1)

But I prefer to address the ParentTable direct. Do you have an idea how?

Thanks,
Ward

  #3  
Old November 19th, 2009, 12:37 PM posted to microsoft.public.word.tables
Ward
external usenet poster
 
Posts: 28
Default Nested Tables

Hi Lene,

Thanks for your answer. I understand that there is no direct adressing, with
a Parent- or Child- methode. Your solution with NestingLevel is more robust
than mine. I will use that. And your methode for "Set Parent" is far better
than mine.
Thanks for helping me futher.

Ward


"Lene Fredborg" wrote:

I am not sure whether you will find the following better:

Dim tblParent As Table
Dim nIndex As Long

If Selection.Tables(1).NestingLevel 1 Then 'nested
'Find the index of the first character before the nested table
'that character is in the parent table
nIndex = Selection.Tables(1).Range.Start
Set tblParent = ActiveDocument.Range.Tables(ActiveDocument.Range(0 ,
nIndex).Tables.Count)
End If

I have tested a little. If you have more nesting levels, the code still
selects the first-level table. I am on my way out just now, so I am not able
to experiment further now. Please post back if needed and I will take a look
later.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ward" wrote:

Hi,
I work in VBA with nested tables. After nested table (a child- or sub-table)
is selected i do some table formatting to both nested table and parent table.
So in my code i want to Set tblParent to the parent table. But i have no idea
how to address the parent table directly. I know that i can move the range by
counting cells like:

Dim tblParent As Table, tblSelection As Table
Dim rng As Range

' with help of the used table.style name i checked if the Child table is
selected if so:
Set tblSelection = Selection.Range.Tables(1)
Set rng = tblSelection.Cell(1, 1).Range
rng.MoveEnd Unit:=wdCell, Count:=-1
Set tblParent = rng.Tables(1)

But I prefer to address the ParentTable direct. Do you have an idea how?

Thanks,
Ward

  #4  
Old November 19th, 2009, 11:05 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Nested Tables

You are welcome. I am glad I could help.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ward" wrote:

Hi Lene,

Thanks for your answer. I understand that there is no direct adressing, with
a Parent- or Child- methode. Your solution with NestingLevel is more robust
than mine. I will use that. And your methode for "Set Parent" is far better
than mine.
Thanks for helping me futher.

Ward


"Lene Fredborg" wrote:

I am not sure whether you will find the following better:

Dim tblParent As Table
Dim nIndex As Long

If Selection.Tables(1).NestingLevel 1 Then 'nested
'Find the index of the first character before the nested table
'that character is in the parent table
nIndex = Selection.Tables(1).Range.Start
Set tblParent = ActiveDocument.Range.Tables(ActiveDocument.Range(0 ,
nIndex).Tables.Count)
End If

I have tested a little. If you have more nesting levels, the code still
selects the first-level table. I am on my way out just now, so I am not able
to experiment further now. Please post back if needed and I will take a look
later.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ward" wrote:

Hi,
I work in VBA with nested tables. After nested table (a child- or sub-table)
is selected i do some table formatting to both nested table and parent table.
So in my code i want to Set tblParent to the parent table. But i have no idea
how to address the parent table directly. I know that i can move the range by
counting cells like:

Dim tblParent As Table, tblSelection As Table
Dim rng As Range

' with help of the used table.style name i checked if the Child table is
selected if so:
Set tblSelection = Selection.Range.Tables(1)
Set rng = tblSelection.Cell(1, 1).Range
rng.MoveEnd Unit:=wdCell, Count:=-1
Set tblParent = rng.Tables(1)

But I prefer to address the ParentTable direct. Do you have an idea how?

Thanks,
Ward

 




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 12:40 AM.


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