Setting Table Cell Margins/Padding to "Same as the Whole Table".

F

Fred Holmes

Word 2003

In a Table, using a macro, I am trying to set the cell margins/padding
back to the "default" value. This operation is accomplised manually
by:

Tables => Table Properties => Cell => Options => Cell Margins =>
checkbox: Same as the whole table. (which sets "cell padding")

I can do the inverse, customize the cell padding to explicit custom
values for the cell with, e.g., the following working vba code:

With Selection.Cells(1)
.TopPadding = InchesToPoints(0.05)
.BottomPadding = InchesToPoints(0.05)
.LeftPadding = InchesToPoints(0.05)
.RightPadding = InchesToPoints(0.05)
.WordWrap = True
.FitText = False
End With

which code was obtained by recording "keystrokes" (mouse clicks and
keystrokes).

If I then run a record-keystroke macro to remove the custom padding
from the cell I get only the last two lines of code (.WordWrap and
..FitText). The "TopPadding =", etc., statements are missing
altogether. But running this "remove" macro doesn't work. The
existing custom padding/margins in the selected cell remains.

Is there a VBA statement that will remove the custom padding from the
selected cell and set it to the value assigned for the entire table?

I've tried:

.TopPadding = Nothing
and
.TopPadding = -1

Neither work. If I write code to query the value, it returns -1, but
if I try to set it to -1 the error message says that the value to be
set must be between 0 and some positive number (I forget the exact
value).

Thanks,

Fred Holmes

I chose to post this under "Tables" rather than macros or VBA, and did
not cross-post. Hope I did it correctly.
 
Joined
Jan 3, 2023
Messages
1
Reaction score
0
I asked the openai project (https://chat.openai.com/auth/login) for a macro to set the margins (padding) in all table cells to "Same as entire table" and it generated this code.

Sub SetCellMarginsToSameAsCurrentTable()
Dim tbl As Table
Dim cell As Cell

' Get a reference to the current table
Set tbl = Selection.Tables(1)

' Loop through the cells in the table
For Each cell In tbl.Range.Cells
cell.TopPadding = tbl.TopPadding
cell.BottomPadding = tbl.BottomPadding
cell.LeftPadding = tbl.LeftPadding
cell.RightPadding = tbl.RightPadding
Next cell
End Sub

This macro does what I want, though it does not tick the "Same as entire table" checkbox, so if the table default padding is changed, the macro needs to be run again. Still better than resetting cells one by one.

Amazing AI!
 

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