Results 1 to 1 of 1
Thread: Code: Sub udf_RemoveEmptyCells()
2001-04-12, 19:54 #1
- Join Date
- Feb 2001
- Yilgarn region of Toronto, Ontario
- Thanked 0 Times in 0 Posts
Code: Sub udf_RemoveEmptyCells()
OK. So now I have all these tables in a document, and I've deleted contents of cells i don't want.
Now I want to rip through the document getting rid of all empty cells (after which I'll convert all tables to tabs).
The code below uses the collection of tables for the outer loop, but reverts to an integer For-loop for the inner loops. I've had very little success in looping through a collection of objects where I'm deleting (or even modifying!) some of the objects in the collection.
' Procedure : udf_RemoveEmptyCells
' Description: Remove all empty cells from all tables in the active document.
' By: Chris Greaves Inc.
' Inputs: None.
' Returns: None
' Assumes: Nothing
' Side Effects: None.
' Tested: By a call from the user.
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
' Can't For-loop on a collection when we are deleting members of the collection.
Dim iRow As Integer
Dim iCol As Integer
For iRow = tbl.Rows.Count To 1 Step -1
For iCol = tbl.Columns.Count To 1 Step -1
' Here I should really make use of Function boolOnlyWhiteSpace
If Len(tbl.Cell(Row:=iRow, Column:=iCol).Range.Text) <= 2 Then