Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Location
    Chicago, Illinois, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adjusting Formatting In All Sections of a Document (Word 2002)

    Trying to write a macro to adjust page setup options in a document containing sections. I can get it to work in section 1, have tried different code to loop through all sections, but have not succeeded. Below is what works in one section. Help is greatly appreciated.

    With ActiveDocument
    .UpdateStylesOnOpen = True
    .AttachedTemplate = "h:importSpecifications.dot"
    End With
    With ActiveDocument
    .UpdateStylesOnOpen = False
    End With

    With Selection.PageSetup

    .LineNumbering.Active = False
    .TopMargin = InchesToPoints(1.1)
    .BottomMargin = InchesToPoints(1)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(1)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.27)
    .PageHeight = InchesToPoints(11.69)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin

    End With

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adjusting Formatting In All Sections of a Document (Word 2002)

    Code like the following will loop through all sections:

    Dim sec As Section
    For Each sec In ActiveDocument.Sections
    With sec.PageSetup
    .LineNumbering.Active = False
    .TopMargin = InchesToPoints(1)
    .BottomMargin = InchesToPoints(1)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(1)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PaperSize = wdPaperA4
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    End With
    Next sec
    Set sec = Nothing

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adjusting Formatting In All Sections of a Document (Word 2002)

    Why enumerate all the sections? Why not just apply the settings to the whole document?

    Try this.

    With Activedocument.PageSetup
    .LineNumbering.Active = False
    .TopMargin = InchesToPoints(1.1)
    .BottomMargin = InchesToPoints(1)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(1)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.27)
    .PageHeight = InchesToPoints(11.69)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    End With


    Regards,
    Kevin Bell

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adjusting Formatting In All Sections of a Document (Word 2002)

    That is a lot easier. Looping, on the other hand, would allow you to vary the settings according to some condition or other.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •