Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2022, 09:02 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2019
Competent Performer
Help with Tables in All Headers in Every Section - Remove cell's padding
 
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
  #2  
Old 02-27-2022, 11:27 PM
Guessed's Avatar
Guessed Guessed is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this version. Your code was setting up lots of nested loops but then ignoring that and just working on the selected table, over and over again.
Code:
Sub aaa()
  Dim oSec As Section, oHead As HeaderFooter
  Dim oTbl As Table, oCell As Cell
  For Each oSec In ActiveDocument.Sections
    For Each oHead In oSec.Headers
      For Each oTbl In oHead.Range.Tables
        With oTbl
          'this would be the preferred method
          .RightPadding = 0
          .LeftPadding = 0
          .TopPadding = 0
          .BottomPadding = 0
          .Spacing = 0
          'and include 'same as table' for all cells
          'But there isn't a method to make all cells 'same as table' other than with SendKeys
          '... instead we will assign the same settings to every cell
          For Each oCell In oTbl.Range.Cells
            With oCell
              .TopPadding = 0
              .BottomPadding = 0
              .LeftPadding = 0
              .RightPadding = 0
            End With
          Next oCell
        End With
      Next oTbl
    Next oHead
  Next oSec
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-27-2022, 11:44 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2019
Competent Performer
Help with Tables in All Headers in Every Section - Remove cell's padding
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Red face Andrew, you miracle worker - I bow to thank you

OMG, you've done it.
Yeah I know I was in a loop and couldn't figure out how to getmyself out of that mess.

I'm soooooo greateful, and thankful, to have help me out again.

I was beyond fedup of fixing these two problems, well actually, one problem since my macro for every ''Table'' padding worked, on each tables, from every section header, on every page.

Thank you, from the bottom of my heart

Cendrinne
Reply With Quote
  #4  
Old 02-28-2022, 12:07 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2019
Competent Performer
Help with Tables in All Headers in Every Section - Remove cell's padding
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Smile Andrew, another quick question.....

Could I use part of your script to place a style on each rows?

I have a given style name on row 1=".Name of account_header"
I have a given style name on row 2=".Name of Tbl_header"
I have a given style name on row 3=".Period_header"
I have a given style name on row 4=".empty_row_space_header"

But what will happen if I have a table with less rows?
Like there are sections where it's only two rows, and some 1.

Does this resolves the issues = On Error GoTo 0? or On Error GoTo Next?

Maybe I should have created a new Thread, but I wanted to ask in regards to your start of the script to have it go in headers. Not sure how to do it, but was wondering if its doable?

Any insights, I would be grateful

Cendrinne
Reply With Quote
  #5  
Old 02-28-2022, 03:01 PM
Guessed's Avatar
Guessed Guessed is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It is easy enough to assign paragraph styles to the tables as you go. You can code it to do a whole row but if any table has vertically merged cells then you will need to be able to handle the error that arises from that approach. Instead, you can take the slower path of applying styles at the cell level which avoids that possible error. I've highlighted the code to add showing where it sits in the above code.
Code:
          For Each oCell In oTbl.Range.Cells
            With oCell
              .TopPadding = 0
              .BottomPadding = 0
              .LeftPadding = 0
              .RightPadding = 0
              Select Case .RowIndex
                Case 1
                  .Range.Style = "Heading 1"
                Case 2
                  .Range.Style = "Heading 2"
                Case 3
                  .Range.Style = "Heading 3"
                Case Else
                  .Range.Style = "Heading 4"
              End Select
            End With
          Next oCell
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 03-02-2022, 12:37 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2019
Competent Performer
Help with Tables in All Headers in Every Section - Remove cell's padding
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Red face Hello Andrew, is Heading = Header area (as header and footer)?

Hi Andrew,

I would have thought the script need to tell the range to go to the Header.

Or am I wrong to assume this?

Cendrinne
Reply With Quote
  #7  
Old 03-06-2022, 04:26 AM
Guessed's Avatar
Guessed Guessed is offline Help with Tables in All Headers in Every Section - Remove cell's padding Windows 10 Help with Tables in All Headers in Every Section - Remove cell's padding Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The code is already inside the cell in the table in the header in the section.

There is no need to go back and re-specify the header
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
cells padding removal, help me;



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Tables in All Headers in Every Section - Remove cell's padding Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Wild Bee Word VBA 3 02-10-2021 12:44 AM
Help with Tables in All Headers in Every Section - Remove cell's padding Headers and footers cross section breaks baymoon Word 2 05-15-2017 09:01 PM
Help with Tables in All Headers in Every Section - Remove cell's padding Typesetting agony: section breaks, footers, and headers, oh MY... thesun Word 6 05-29-2015 11:55 AM
Help with Tables in All Headers in Every Section - Remove cell's padding remove headers and footers ghphoto Word 2 02-22-2015 05:49 PM
Help with Tables in All Headers in Every Section - Remove cell's padding Using Pagination, Headers and Section Endnotes Simultaneously DBinSJ Word 4 05-01-2012 02:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft