View Single Post
 
Old 02-27-2022, 09:02 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Default Help with Tables in All Headers in Every Section - Remove cell's padding

Hello Pros,
I got this 110 pages document, where almost all pages has a sections break with the headers having a different name.

What is annoying, is that it's put Cell inside padding space. I was able to create a macro to remove all tables padding. But lot's of tables still had space in there. Not even consistant from one page to another. I'm so fedup to fix them one page at the time.
What you need to know, every page that has a table in the header, its between 2 rows to 4 rows.

I've created a macro to fix the cell padding, but I've created a problem, that it kept staying at that section page. I've tried with F8, step by step, and yup, it stayed stuck there.

Code:
    Dim lngIndex As Long
    Dim oSec As Section
    Dim oHead As HeaderFooter
    Dim i As Integer

     For Each oSec In ActiveDocument.Sections
         For lngIndex = 1 To 3
         
            For Each oHead In oSec.Headers
               If oHead.Exists Then
               For i = oHead.Range.Tables.Count To 1 Step -1
          
                  With oHead.Range.Tables(i)
                  
'***Removes cells padding too
                Dim oCell As Cell
                Dim oTable As Table
                 Set oTable = Selection.Tables(1)
                 For Each oCell In oTable.Range.Cells
                     With oCell
                        .TopPadding = (0)
                        .BottomPadding = (0)
                        .LeftPadding = (0)
                        .RightPadding = (0)
                     End With
                 Next oCell
                  End With
   
               Next i
               End If
            Next oHead
    On Error GoTo 0
  
    Next
  Next

lbl_Exit:
  Exit Sub


By the way, I'll share which one works, it's to remove all table padding from every section. So if this could be done also for the Cells paddings.
I've created to test the tables in the headings, to place 1 space after each row. It works

Code:
  
    Dim lngIndex As Long
    Dim oSec As Section
    Dim oHead As HeaderFooter
    Dim i As Integer

     For Each oSec In ActiveDocument.Sections
         For lngIndex = 1 To 3
         
            For Each oHead In oSec.Headers
               If oHead.Exists Then
               For i = oHead.Range.Tables.Count To 1 Step -1
                'oHead.Range.Tables(i).Delete
                 oHead.Range.Tables(i).Rows.HeightRule = wdRowHeightAuto
                 oHead.Range.Tables(i).Rows.Height = InchesToPoints(0)
                 oHead.Range.Tables(i).Range.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
                 oHead.Range.Tables(i).Range.ParagraphFormat.SpaceBefore = 0
                 oHead.Range.Tables(i).Range.ParagraphFormat.SpaceAfter = 1
          
                 'With Selection.Tables(1)
                  With oHead.Range.Tables(i)
                    .TopPadding = InchesToPoints(0)
                    .BottomPadding = InchesToPoints(0)
                    .LeftPadding = InchesToPoints(0)
                    .RightPadding = InchesToPoints(0)
                    .Spacing = 0
                    .AllowPageBreaks = True
                    .AllowAutoFit = False
                  End With
   
               Next i
               End If
            Next oHead
    'Next oSec
    On Error GoTo 0
  
    Next
  Next

lbl_Exit:
  Exit Sub
Anyway, if any chance you may tell me if it's doable to add or a separate macro to remove all section header tables cell's padding to 0" on each sides, and guide me where I'm going wrong, I would be soooooooo appreciative it

Cendrinne
Reply With Quote