Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Aug 2001
    Location
    Hampshire, England
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    page setup macros (word97 sr2)

    We have internal documents on A4 (& occasional A3 sections) with predefined margin/header/footer sizes. Sometimes I'll get docs back that users have mucked up by pasting in section-loads of their own text, which may have been on US-letter with daft margins or whatnot, and I'm trying to do a macro which turns all letter sections to A4, all 11x17 sections to A3, and fixes the margins. All ok so far. The problem is page orientation: if the macro encounters a landscape A4 section, as soon as it runs the line to set the header distance, it also flips the section to portrait! Why? And how can I tell it to leave the orientation alone?

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: page setup macros (word97 sr2)

    Take a look at your macro code in the VBA editor. Chances are that it picked up the orientation in recording a macro. If so, try putting an apostrophe at the beginning of the line to comment it out. Then try it again.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Star Lounger
    Join Date
    Aug 2001
    Location
    Hampshire, England
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: page setup macros (word97 sr2)

    Hmmm. Thanks for the response Chas: that's what I would have thought if I'd recorded it, but (more fool me) I wrote it in the VBE. As I said, the line that flips the orientation appears to only refer to the header distance:
    (Excuse my--probably rotten--coding style, but this is what I've got, see what you make of it). The documents are all single-sided and the idea is that letter and 11x17 sheets get clobbered, and then A4 and A3 sheets all get the wide margin on the 297mm-long side, be it the top or the left...

    Public Sub SectionTidy()
    Dim Sect1 As Section

    For Each Sect1 In ActiveDocument.Sections

    If Sect1.PageSetup.PaperSize = wdPaperLetter Then
    Sect1.PageSetup.PaperSize = wdPaperA4
    ElseIf Sect1.PageSetup.PaperSize = wdPaper11x17 Then
    Sect1.PageSetup.PaperSize = wdPaperA3
    End If

    With Sect1.PageSetup
    .HeaderDistance = InchesToPoints(0.49) 'this is where it flips landscapes to portrait?!
    .FooterDistance = InchesToPoints(0.49)
    If Sect1.PageSetup.PaperSize = wdPaperA4 And Sect1.PageSetup.Orientation = wdOrientLandscape Then
    .TopMargin = InchesToPoints(1)
    .BottomMargin = InchesToPoints(0.5)
    .LeftMargin = InchesToPoints(0.75)
    .RightMargin = InchesToPoints(0.75)
    Else
    .TopMargin = InchesToPoints(0.75)
    .BottomMargin = InchesToPoints(0.75)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(0.5)
    End If
    End With

    Next Sect1

    End Sub

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: page setup macros (word97 sr2)

    What happens if you temporarily comment out the two lines - about headerdistance and footerdistance - and then run the code?

  5. #5
    Star Lounger
    Join Date
    Aug 2001
    Location
    Hampshire, England
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: page setup macros (word97 sr2)

    Ah. It gets to the "if...and...then..." line and THEN flips the orientation. Stepping through, I see that right at the start, after it changes Letter to A4, the margins seem to flip to portrait margins (I have "show text boundaries" checked), then the page orientation flips later to match it. So do you think it's the order I'm specifying things in?
    I can see that I could probably get around this by making the macro assign the section's orientation to some variable right at the start, and then applying it back to the section right at the end before it moves to the next section (although would that play with the margins again?), but that seems like it would be a bit of a kludge, doesn't it?

Posting Permissions

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