Quick way to adjust table cell margins

D

Dennis S

I need to adjust the cell margins for all cells in a table. Through the user
interface it appears this can be done by selecting the column(s) of the table
and adjusting the table cell properites (i.e. Table>Table Properties...,Cell,
Options, Top, Left,Right, Bottom) - very quick. However, through VBA code
this is only applicable to the Table (default for entire table) or Cell, not
column. The default table values does not help since a table which already
has cell margins set are not overridden by the table default properties.
The cell overrides the table properties.

When coding for each cell, this can be more time consuming than the user
interface sine the code has to navigate each cell (which may be very slow for
large tables (over 100 cells).

This is my code:

Dim oRow as Row
Dim oCell as Cell

For Each oRow in ActiveDocument.tables(2).rows
For Each oCell in oRow.Cells
With oCell
.TopPadding = InchestoPoints(0)
.BottomPadding = InchestoPoints (0)
.LeftPadding = InchesToPoints(0.5)
.RightPadding = InchestoPoints (0)
End With
Next oCell
Next oRow

Any suggestions for improving the processing time for large table
adjustments?
 
C

CodeDawg

Dennis,

I'm not too sure about your concern for table padding not overriding
individual cell implementations of padding. I would think that if
you have not invoked any individual cell padding, that the following would
work.

With ActiveDocument.Tables(2)
.RightPadding = 0#
.LeftPadding = 0.5
.TopPadding = 0#
.BottomPadding = 0#
End With

Now if you want to format some individual cells, the scheme
you are using will override this. I'm not sure, but I don't think
the above code will override any individual cell padding implementation that
was performed previously on the table, so
invoke this code right after you create the table.

I'll watch and see if someone else has alternative methods...
as I am doing something simillar with different cell properties
on tables that have 20,000 cells.

Regards
 
D

Dennis S

The need is for converted tables from Framemaker to WORD; they are not being
created from scratch. The tables were converted from Framemaker to WORD via
a built-in Framemaker convertor (RTF) which preserves the tables as they were
created. The RTF version seems to preserve the original cell margin values,
but these values do not match our standarized values. Therefore, we need to
globally replace these values for the table. It would be nice to select
either the entire table or the columns from the table. It seems that padding
is not available through column selection via VBA. The performance on
navigating each cell within a table is not acceptable for large tables (i.e.
those in excess of 1,000 cells). Also, it appears the "Same as Whole Table"
option (from the user interface) on a cell in not available. Any ideas are
appreciated......
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGVubmlzIFM=?=,
I need to adjust the cell margins for all cells in a table. Through the user
interface it appears this can be done by selecting the column(s) of the table
and adjusting the table cell properites (i.e. Table>Table Properties...,Cell,
Options, Top, Left,Right, Bottom) - very quick. However, through VBA code
this is only applicable to the Table (default for entire table) or Cell, not
column. The default table values does not help since a table which already
has cell margins set are not overridden by the table default properties.
The cell overrides the table properties.
Try selecting the column, then applying the property to the SELECTION.Cells

That's the only way to quickly process an entire column or group of cells that
aren't in a contiguous line (row).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
D

Dennis S

Cindy:
Thanks for your input.

It is true you can select the entire column of a table by:
ActiveDocument.tables(2).columns(1).selection

However, the methods and properties are limited and not the same as the WORD
user interface. For example, one cannot set the left margin of all cells in
a particular column through VBA (leftpadding property is not available) on
existing WORD tables. It is only available on a indivdual cell basis.
Therefore, one would have to naviagate each cell in a column which is
prohibitively intensive for a large table.

Any other ideas?
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGVubmlzIFM=?=,
It is true you can select the entire column of a table by:
ActiveDocument.tables(2).columns(1).selection

However, the methods and properties are limited and not the same as the WORD
user interface. For example, one cannot set the left margin of all cells in
a particular column through VBA (leftpadding property is not available) on
existing WORD tables. It is only available on a indivdual cell basis.
Therefore, one would have to naviagate each cell in a column which is
prohibitively intensive for a large table.

Any other ideas?
SendKeys " %l1{Enter}"
Dialogs(wdDialogTableCellOptions).Show

Will work on the selection. That the dialog box "blinks" isn't pretty. But it
works.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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