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  

Recursive procedure for nested tables



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2009, 06:38 AM posted to microsoft.public.word.tables
TimvG
external usenet poster
 
Posts: 12
Default Recursive procedure for nested tables


Suppose you have nested tables, with the nesting going arbitrarily
deep. You want to do something to every table. It seems that it
would be sensible to use a recursive procedure.

Does anyone have/know of any examples of recursive procedures for
working with nested tables?

Or is there any reason this can't be done?
  #2  
Old December 9th, 2009, 09:56 AM posted to microsoft.public.word.tables
TimvG
external usenet poster
 
Posts: 12
Default Recursive procedure for nested tables

Well, let me be first to reply... It can certainly be done. I can
share some example code if there's interest.

On Dec 9, 4:38*pm, TimvG wrote:
Suppose you have nested tables, with the nesting going arbitrarily
deep. *You want to do something to every table. *It seems that it
would be sensible to use a recursive procedure.

Does anyone have/know of any examples of recursive procedures for
working with nested tables?

Or is there any reason this can't be done?


  #3  
Old December 9th, 2009, 02:17 PM posted to microsoft.public.word.tables
Greg Maxey[_2_]
external usenet poster
 
Posts: 649
Default Recursive procedure for nested tables

Tim,

This is what I use. The example adds a red border to a specific cell in
each main and nested table:

Sub FormatTables()
Dim oTbl As Table
Dim oCell As Word.Cell
For Each oTbl In ActiveDocument.Tables
ProcessTable oTbl 'Process main table
'Call recursive function to process nested tables
RecursiveLoop oTbl
Next
End Sub

Function RecursiveLoop(ByRef oTblParent As Word.Table, Optional oTblChild As
Word.Table)
Dim oCellNested As Word.Cell
Dim oTblNested As Word.Table
Dim i As Long
For Each oCellNested In oTblParent.Range.Cells
If oCellNested.Tables.Count 0 Then
For i = 1 To oCellNested.Tables.Count
Set oTblNested = oCellNested.Tables(i)
Set oTblParent = oTblNested
ProcessTable oTblNested
RecursiveLoop oTblNested, oTblParent
Next i
End If
Next oCellNested
End Function

Sub ProcessTable(oTblSingle As Table)
oTblSingle.Cell(1, 3).Borders.OutsideColorIndex = wdRed
End Sub


"TimvG" wrote in message
...
Well, let me be first to reply... It can certainly be done. I can
share some example code if there's interest.

On Dec 9, 4:38 pm, TimvG wrote:
Suppose you have nested tables, with the nesting going arbitrarily
deep. You want to do something to every table. It seems that it
would be sensible to use a recursive procedure.

Does anyone have/know of any examples of recursive procedures for
working with nested tables?

Or is there any reason this can't be done?



 




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 08:41 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.