Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Thanked 0 Times in 0 Posts

    Word 2003 macro to set table cell margins to 'Same (Word 2003)

    Macro to set cell margins to "Same as the whole table."

    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

    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

    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
    .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


    Fred Holmes

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Word 2003 macro to set table cell margins to '

    Hmmm, I don't know how to check that box. The table that contains the cell does store default information, and you can at least tap into that to set the settings directly. The following code assumes that the first table in the range returned by the cell's .Range property is the one with the correct settings. I have only tested this lightly, so if it fails under certain circumstances, you can either post it here for more input or develop a workaround that works for you. Or both. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    <pre>Sub FixCurrentCell()
    SetCellPaddingToDefault Selection.Cells(1)
    End Sub

    Sub SetCellPaddingToDefault(myCell As Word.Cell)
    Dim tbl As Word.Table
    With myCell
    Set tbl = .Range.Tables(1)
    .TopPadding = tbl.TopPadding
    .BottomPadding = tbl.BottomPadding
    .LeftPadding = tbl.LeftPadding
    .RightPadding = tbl.RightPadding
    End With
    If Not (tbl Is Nothing) Then Set tbl = Nothing
    If Not (myCell Is Nothing) Then Set myCell = Nothing
    End Sub</pre>

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts