View Single Post
 
Old 02-27-2022, 11:27 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
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