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?
|