![]() |
|
|
|
#1
|
||||
|
||||
|
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
![]() Cendrinne |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
||||
|
||||
|
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 |
|
| Tags |
| cells padding removal, help me; |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Headers and footers cross section breaks
|
baymoon | Word | 2 | 05-15-2017 09:01 PM |
Typesetting agony: section breaks, footers, and headers, oh MY...
|
thesun | Word | 6 | 05-29-2015 11:55 AM |
remove headers and footers
|
ghphoto | Word | 2 | 02-22-2015 05:49 PM |
Using Pagination, Headers and Section Endnotes Simultaneously
|
DBinSJ | Word | 4 | 05-01-2012 02:33 AM |