Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jan 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to replace Section Breaks with Page Breaks (XP)

    I have a large document with many Section Breaks.

    How can I replace the Section Breaks with Page Breaks so that I can use the Print|Pages... to select what I want to print???

    The Edit|Replace... using the "Special" icon and the resulting ^b; ^m characters doesn't work. I can remove all Section Breaks, but the Replace with manual Page Break just wipes out everything...

    ash

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How to replace Section Breaks with Page Breaks (XP)

    If you look at the section breaks in Normal view, what kind are they? That find and replace works fine with Next Page breaks in my test in Word 2000, but maybe other kinds are problematic?

    Regarding printing, Word recognizes the odd syntax p1s2 to mean "page 1 of section 2." You can span almost any arbitrary range of sections and pages with this syntax.

  3. #3
    New Lounger
    Join Date
    Jan 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to replace Section Breaks with Page Breaks (XP)

    Jeff-

    The macro is really neat ;-) Works fine in XP

    You asked above what kind of Section Breaks they were. They are "Next Page" !!!

    I'm a light-weight when it comes to VB and macros so I have what is probably a real dumb question:
    When I pasted in the macro in VB, the "Option Explicit" appears "above the line" as shown in the attachment. I never saw that before nor do I know what it means. Can you enlighten me a bit.

    Thanks

    ash
    Attached Images Attached Images

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: How to replace Section Breaks with Page Breaks (XP)

    The Option Explicit line is not part of the macro itself but it sets the environment for that module so that any variables used must be declared. This is good programming practice as described on one of the MSDN pages. I don't know that I would describe it myself as a coding blunder of the HIGHEST ORDER but it is something useful to add.
    <hr> Using the Option Explicit Statement
    Neither VBScript nor VBA requires you to declare variables before using them. The default behavior in both languages is to allow you to create variables by simply using a variable name in an assignment statement.

    However, every experienced developer knows that the failure to use the Option Explicit statement to force explicit variable declaration is a coding blunder of the highest order. Using undeclared variables can introduce subtle, hard-to-find bugs into your code that are easily avoided by using this one, simple technique.

    To force VBA to insert the Option Explicit statement in every module you create, open the Visual Basic Editor, click Options on the Tools menu, and then click Require Variable Declaration on the Editor tab.

    To force variables to be declared in VBScript, type Option Explicit immediately after the first <SCRIPT> tag in your HTML document.<hr>
    If you do a search on google for "Option Explicit declare variables VBA" you will find plenty of pages to describe the Option Explicit statement.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How to replace Section Breaks with Page Breaks (XP)

    Andrew nailed it, but for future reference, the "select blue-colored wording and press F1" technique works pretty well in the VB Editor, far better than it does in the Office programs themselves. You can unlock the meaning of a lot of mysterious code that way.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Print selection of pages across section breaks

    (Edited by jscher2000 on 14-May-04 08:53. )

    I realize that p1s2 syntax is a hassle, so how about a macro? Try this out on your document:
    Code:
    Option Explicit
    
    Sub PrintSelectedPageRange()
    ' Jefferson Scher 7 Dec 2002; patched 14 May 2004 to address issue in post 372414 
    ' Macro to print the range of pages in the selection
    Dim rngStart As Range, rngEnd As Range, strPrintRange As String
    ' To retrieve page and section numbers, set two range variables
    With Selection
        Set rngStart = ActiveDocument.Range(.Start, .Start)
        If .End <> ActiveDocument.Range.End Then
            Set rngEnd = ActiveDocument.Range(.End, .End)
        Else 'new stuff 14 May 2004 to address end of document error
            Set rngEnd = ActiveDocument.Range.Duplicate
            rngEnd.Collapse wdCollapseEnd
        End If
    End With
    ' Note that we used the user-assigned "logical" page number,
    ' not the physical page number in the p1s2 syntax
    strPrintRange = _
        "p" & rngStart.Information(wdActiveEndAdjustedPageNumber) & _
        "s" & rngStart.Information(wdActiveEndSectionNumber) & "-" & _
        "p" & rngEnd.Information(wdActiveEndAdjustedPageNumber) & _
        "s" & rngEnd.Information(wdActiveEndSectionNumber)
    ' Clean up the objects
    Set rngStart = Nothing
    Set rngEnd = Nothing
    ' Pre-populate and display the File|Print... dialog
    With Dialogs(wdDialogFilePrint)
        .Range = wdPrintRangeOfPages
        .Pages = strPrintRange
        .Show   ' displays and executes
    End With
    End Sub
    This was tested in Word 2000. Does it work as expected in XP?

    Note: Updated version was tested in Word 2002.
    Last edited by jscher2000; 2011-02-03 at 11:50. Reason: Tags adapted to new lounge

Posting Permissions

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