Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Nov 2012
    Posts
    20
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Page Break macro

    Hi, we are running Office 2010/Win 7. I'm trying to create a macro for Word that will remove the Layout/Break/Page break option and replace it with the paragraph, page break before option. I don't want any section breaks removed, just the page breaks.

    I have some scientific authors who get carried away with adding page breaks and sometimes it messes up the template styles (I don't know why). However, the page break before have proven to be an easy fix. Since some of the docs can get above the 100 page mark, I'd like to automate this step to find any page break and replace it with the page break before.

    Any suggestion will be helpful.

    Thanks,

    Chris Bowman
    Last edited by the_couchguards; 2013-10-28 at 08:52.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Chris,

    No code needed just do a Find & Replace {Ctrl+H} as follows:
    PageBreaks.JPG
    Use the Replace All button. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    New Lounger
    Join Date
    Nov 2012
    Posts
    20
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi,

    Unfortunately, it did not add the "page break before" option to these sections, just removed the page break.

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Chris,

    OOPS!
    I forgot the formatting.
    PageBreaks.JPG
    Press the Format button to change the formatting while the cursor is in the Replace With box. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. The Following User Says Thank You to RetiredGeek For This Useful Post:

    the_couchguards (2013-10-29)

  6. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I think it is odd that you want to replace a hard page break with a paragraph formatted page break.

    You say this is because it "sometimes messes up the the template styles". Perhaps this is due to the author sometimes not including a paragraph mark at the location of the page break which effectively ensures that the 'paragraphs' either side of the hard page break are actually in the same paragraph and therefore share the same paragraph style. The posted solution of replacing the hard page break with a paragraph mark will solve this problem but will also result in extra empty paragraphs in most cases.

    Rather than adding a 'page break before' paragraph formatting attribute you should be looking to rely on the paragraph styles that are already applied to do this for you. Each heading for instance should have 'keep with next' turned on already. IMO, doing a global replace of hard page breaks with paragraph formatted page breaks is missing the point.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #6
    New Lounger
    Join Date
    Nov 2012
    Posts
    20
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi Andrew,

    I totally agree with you. The issue I'm having is that I have many clients with many versions of templates created by different people and they don't want me to fix it, no matter how much I tell them that in the long run it would be easier to fix now. So, some come in great with no issues and others come in needing help.

    Thanks for your help and feedback.

    Chris

  8. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Integer
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^m"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Do While .Find.Found
        i = i + 1
        If .Characters.Last.Previous <> vbCr Then
          .Text = vbCr
        Else
          .Text = vbNullString
        End If
        .Characters.Last.Next.Paragraphs.First.PageBreakBefore = True
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    MsgBox i & " instances found & updated."
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. The Following 2 Users Say Thank You to macropod For This Useful Post:

    Charles Kenyon (2013-10-29),the_couchguards (2013-10-29)

Posting Permissions

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