none
Word 2016 Tables: How to find cells with cell margins greater than "0" RRS feed

  • Question

  • Hi all,

    I have to standardize formatting of some documents created by different users.
    These documents contain hundreds of tables where users sometimes applied cell margins between 0,05 cm and 0,15 cm to special cells.

    Unfortunately, you cannot select a table and change/reset cell margins all at once. You have to control and edit nearly each single cell.

    It would save me a lot of time to find out those cells and apply margins of 0 cm ("Same as the whole table").
    There are also cell margins of 0,2 cm - they should be maintained.

    Any help appreciated.

    Regards from Germany,
    Lisa

    Tuesday, October 30, 2018 1:46 PM

Answers

  • Try:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Tbl As Table, Cll As Cell, b As Single, l As Single, r As Single, t As Single
    For Each Tbl In ActiveDocument.Tables
      With Tbl
        b = .BottomPadding
        l = .LeftPadding
        r = .RightPadding
        t = .TopPadding
        For Each Cll In .Range.Cells
          With Cll
            If .BottomPadding <> CentimetersToPoints(1 / 5) Then .BottomPadding = b
            If .LeftPadding <> CentimetersToPoints(1 / 5) Then .LeftPadding = l
            If .RightPadding <> CentimetersToPoints(1 / 5) Then .RightPadding = r
            If .TopPadding <> CentimetersToPoints(1 / 5) Then .TopPadding = t
          End With
        Next
      End With
    Next
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, October 31, 2018 12:08 AM

All replies

  • Try:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Tbl As Table, Cll As Cell, b As Single, l As Single, r As Single, t As Single
    For Each Tbl In ActiveDocument.Tables
      With Tbl
        b = .BottomPadding
        l = .LeftPadding
        r = .RightPadding
        t = .TopPadding
        For Each Cll In .Range.Cells
          With Cll
            If .BottomPadding <> CentimetersToPoints(1 / 5) Then .BottomPadding = b
            If .LeftPadding <> CentimetersToPoints(1 / 5) Then .LeftPadding = l
            If .RightPadding <> CentimetersToPoints(1 / 5) Then .RightPadding = r
            If .TopPadding <> CentimetersToPoints(1 / 5) Then .TopPadding = t
          End With
        Next
      End With
    Next
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, October 31, 2018 12:08 AM
  • Hi Lisa,

    Did macropod's answer resolved your problem?

    You can mark it as answer if it helped and please help us close the thread.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    • Edited by Lina-MSFT Wednesday, October 31, 2018 9:15 AM
    Wednesday, October 31, 2018 2:16 AM
  • Hi Paul,

    You've made my day! While drinking a cup of coffee I can watch the code working for me :-).
    Hope, other users will find it helpful, too.

    Thank you so much,

    Lisa




    Wednesday, October 31, 2018 9:13 AM