Discussion:
nested tables
(too old to reply)
Robert
2011-03-25 19:33:52 UTC
Permalink
Hi Jason,

I have the same issue with a doc I'm working on. Did you ever figure out the code to automatically get rid of empty nested tables?

Thanks,

Rob
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.
If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you will
need some sort of macro.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
Sub DeleteEmptyRows_AllTables()
Dim oTable As Table
Dim oRow As Row
For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable
End Sub
The macro iterates through all tables in the active document and finds (and
deletes) the empty rows by checking the total string length of each row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of 2
Therefore, the row is empty if the string length is equal to the number of
cells in the row multiplied by 2 + 2.
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm
NOTE that both macro versions will fail if the table contains vertically
merged cells (requires some error handling).
http://www.gmayor.com/installing_macro.htm
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.
May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.
David,
could you please post the code for iterating through the nested tables. I am having this exact issue, but my coding skills are lacking. Thanks.
Jason
Suzanne S. Barnhill
2011-03-25 20:10:46 UTC
Permalink
If you just want to unnest them, then when you use Table | Convert | Table
to Text, you're asked if you want to convert nested tables as well. (This is
set On by default). After converting, you can convert Text back to Table.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
Post by Robert
Hi Jason,
I have the same issue with a doc I'm working on. Did you ever figure out
the code to automatically get rid of empty nested tables?
Thanks,
Rob
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.
If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you will
need some sort of macro.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
Sub DeleteEmptyRows_AllTables()
Dim oTable As Table
Dim oRow As Row
For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable
End Sub
The macro iterates through all tables in the active document and finds (and
deletes) the empty rows by checking the total string length of each row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of 2
Therefore, the row is empty if the string length is equal to the number of
cells in the row multiplied by 2 + 2.
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm
NOTE that both macro versions will fail if the table contains vertically
merged cells (requires some error handling).
http://www.gmayor.com/installing_macro.htm
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.
May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.
David,
could you please post the code for iterating through the nested
tables. I am having this exact issue, but my coding skills are
lacking. Thanks.
Jason
Robert
2011-03-25 20:35:36 UTC
Permalink
Thanks for the response, Suzanne.

Much appreciated but my question (sorry it wasn't stated well) was regarding the macro Lene posted long ago that automatically deletes empty rows. The macro works on primary tables, but does not delete empty rows for nested tables.

David wrote that to affect the nested tables you needed to "iterate over oTable.Table". I was wondering what was meant by that and if the code that could do this was readily available.

Cheers.
Post by Suzanne S. Barnhill
If you just want to unnest them, then when you use Table | Convert | Table
to Text, you're asked if you want to convert nested tables as well. (This is
set On by default). After converting, you can convert Text back to Table.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
Post by Robert
Hi Jason,
I have the same issue with a doc I'm working on. Did you ever figure out
the code to automatically get rid of empty nested tables?
Thanks,
Rob
How do i delete blank rows from tables in an automated manner? My table
is
200 pages and contains random blank rows due to another automated
process,
and I want to be able to search/replace blank rows or somehow delete
them.
If the table content is such that it can be sorted, then all blank rows
will
sort to the top and can be easily deleted as a group. Barring that, you
will
need some sort of macro.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
Sub DeleteEmptyRows_AllTables()
Dim oTable As Table
Dim oRow As Row
For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable
End Sub
The macro iterates through all tables in the active document and finds
(and
deletes) the empty rows by checking the total string length of each
row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of
2
Therefore, the row is empty if the string length is equal to the number
of
cells in the row multiplied by 2 + 2.
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm
NOTE that both macro versions will fail if the table contains
vertically
merged cells (requires some error handling).
http://www.gmayor.com/installing_macro.htm
--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
May I add, I have a document that has nested tables that this macro
missed. I
found that I have to iterate over oTable.Tables (which I created
another sub
to do that I called reiteratively). Just thought you would like to
know.
May I add, I have a document that has nested tables that this macro
missed. I
found that I have to iterate over oTable.Tables (which I created
another sub
to do that I called reiteratively). Just thought you would like to
know.
David,
could you please post the code for iterating through the nested
tables. I am having this exact issue, but my coding skills are
lacking. Thanks.
Jason
Loading...