Superfluous Table Columns

R

Rebecca

I am using MS WORD XP. I have literally hundreds of
tables that contain empty columns only at the end of each
table. The tables themselves range from one to nine
columns. Some tables have no empty columns (i.e., they
contain nine columns with words in them), some have one,
two, three, four, and so on, up to eight empty columns,
with no words in them.

Is there any way I can go through these WORD documents
and "automatically" (with a macro or whatever) delete
these empty columns, since they take up space? To go
through the tables and do this by hand will take forever.
I would deeply appreciate your help in this matter.
 
J

Jay Freedman

Rebecca said:
I am using MS WORD XP. I have literally hundreds of
tables that contain empty columns only at the end of each
table. The tables themselves range from one to nine
columns. Some tables have no empty columns (i.e., they
contain nine columns with words in them), some have one,
two, three, four, and so on, up to eight empty columns,
with no words in them.

Is there any way I can go through these WORD documents
and "automatically" (with a macro or whatever) delete
these empty columns, since they take up space? To go
through the tables and do this by hand will take forever.
I would deeply appreciate your help in this matter.

Hi Rebecca

Visit http://www.gmayor.com/installing_macro.htm for instructions on
using this macro:

Public Sub RemoveEmptyColumns()
Dim oTbl As Table
Dim oRow As Row
Dim bEmptyCol As Boolean

For Each oTbl In ActiveDocument.Tables
bEmptyCol = True
Do
For Each oRow In oTbl.Rows
With oRow
' an "empty" cell contains a cell marker
' that appears to VBA as 2 characters
If Len(.Cells(.Cells.Count).Range.Text) > 2 Then
bEmptyCol = False
Exit For
End If
End With
Next oRow

If bEmptyCol Then
If oTbl.Columns.Count > 1 Then
oTbl.Columns.Last.Delete
Else
oTbl.Delete
Exit Do
End If
End If
Loop Until Not bEmptyCol
Next oTbl
End Sub
 
R

Rebecca

Thanks a million, Jay. It worked like a charm.
-----Original Message-----


Hi Rebecca

Visit http://www.gmayor.com/installing_macro.htm for instructions on
using this macro:

Public Sub RemoveEmptyColumns()
Dim oTbl As Table
Dim oRow As Row
Dim bEmptyCol As Boolean

For Each oTbl In ActiveDocument.Tables
bEmptyCol = True
Do
For Each oRow In oTbl.Rows
With oRow
' an "empty" cell contains a cell marker
' that appears to VBA as 2 characters
If Len(.Cells
(.Cells.Count).Range.Text) > 2 Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top