Consulting

Results 1 to 3 of 3

Thread: VBA to set cell margins to "Same as whole table"?

  1. #1
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location

    VBA to set cell margins to "Same as whole table"?

    I want to set margins for all table cells to Same as the whole table, but I can't find the VBA function to do that. I thought maybe LeftPadding, RightPadding, etc. would do it, but I've not found a way to set them to the table default value. I also tried manually setting one cell and then using F4 to repeat for other cells, but that doesn't work either.

    I have found that converting the table to text then back to table resets all cell margins to default, but in my particular case that messed up the table and I had to do considerable manual fixing-up.

    A macro to set all table cells to Same as whole table would be great. Can it be done?

  2. #2
    Padding should do it e.g. the following will apply the default padding, unless you have changed the default, in which case change the numbers to reflect what you have.

    Sub PadAllCells()
    Dim oCell As Cell
        For Each oCell In Selection.Tables(1).Range.Cells
            With oCell
                .TopPadding = CentimetersToPoints(0)
                .BottomPadding = CentimetersToPoints(0)
                .LeftPadding = CentimetersToPoints(0.19)
                .RightPadding = CentimetersToPoints(0.19)
            End With
        Next oCell
        Set oCell = Nothing
    End Sub
    
    
    
    
    Sub PadCurrentCell()
    Dim oCell As Cell
        Set oCell = Selection.Cells(1)
        With oCell
            .TopPadding = CentimetersToPoints(0)
            .BottomPadding = CentimetersToPoints(0)
            .LeftPadding = CentimetersToPoints(0.19)
            .RightPadding = CentimetersToPoints(0.19)
        End With
        Set oCell = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location
    Thanks for the macros. They set cell padding per the specified values but they do not set the Same as the whole table checkbox, which is what I'm after. How can I do that?

Tags for this Thread

Posting Permissions

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