Consulting

Results 1 to 7 of 7

Thread: Extra Manual Page Breaks

  1. #1
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    5
    Location

    Extra Manual Page Breaks

    I have a code that removes tables that are not necessary from a word 2010 document.

    However, there are occasions where I am being left with two manual page breaks. This means I have a blank page.

    What I want is a single page break at the end of the text.

    I am struggling to write a code that will search the active document and replace 2 or more manual page breaks with 1 page break so that there are no blank pages.

    Can anyone assist?

    Thanks for your help.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You should be able to do with a wildcard Find/Replace, where:
    Find = [^12]{2,}
    Replace = ^12
    Of course, this assumes there is nothing else (not even an empty paragraph) between those page breaks. You might want to precede the above Find/Replace with:
    Find = [^12][^13^l^t ]{1,}[^12]
    Replace = ^12
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    5
    Location

    Trying......

    Paul,

    Thank you for the assistance, but clearly I am still just learning!

    Sub Para()

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = [^12]{2,}
    .Replacement.Text = ^12
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    End Sub

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    There are some errors in your code (e.g. omission of quotes enclosing the Find/Replace expressions), it's not using the Wildcards option, even though the Find expression requires it, and it's missing a key ingredient - the .Execute statement! Try:
    Sub Demo()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "[^12]{2,}"
      .Replacement.Text = "^12"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
    End Sub
    PS: When posting code, please use the code tags. They're indicated by the # button on the posting menu.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    5
    Location

    Thank you!

    Thanks for the help!

    If there are multiple pages, It looks like I may have to run this macro multiple times. I setup a loop and it worked!

    Thanks!

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by JeremyS View Post
    If there are multiple pages, It looks like I may have to run this macro multiple times. I setup a loop and it worked!
    You might have set up a loop - but it didn't 'work' because it isn't needed. The code I posted is quite sufficient as is.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    1
    Location
    Thanks for this.

Posting Permissions

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