Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2021, 03:57 AM
Snazzy Snazzy is offline Replace 'Page Break Before' with 'Manual Page Break' Windows 10 Replace 'Page Break Before' with 'Manual Page Break' Office 2019
Novice
Replace 'Page Break Before' with 'Manual Page Break'
 
Join Date: Jun 2020
Posts: 7
Snazzy is on a distinguished road
Default Replace 'Page Break Before' with 'Manual Page Break'

Hi
I'm trying to replace all 'Page Break Before's with 'Manual Page Break' in a document.
As I'm not sure the former has a Find and Replace code like the latter (^m) - which would be the easiest to handle -
I'm trying find a vba way to do this, but none of the following versions works. Can anyone please help?

Sub ReplacePageBreakBefore2ManualPageBreak_v1()
Selection.Find.Replacement.ParagraphFormat.PageBre akBefore = False
With Selection.Find
.Text = ""
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Sub ReplacePageBreakBefore2ManualPageBreak_v2() ' rewrite of slaycock's 'Page Break Before' insertion macro


Dim myParagraph As Paragraph
Dim LastParaIsMyStyle As Boolean
LastParaIsMyStyle = True
For Each myParagraph In ActiveDocument.Paragraphs
If LastParaIsMyStyle Then
myParagraph.PageBreakBefore = False
Selection.InsertBreak Type:=wdPageBreak ' problem here
End If
Next
End Sub

Sub ReplacePageBreakBefore2ManualPageBreak_v3() ' rewrite of slaycock's 'Page Break Before' insertion macro
Dim myParagraph As Paragraph
Dim LastParaIsMyStyle As Boolean
LastParaIsMyStyle = True
For Each myParagraph In ActiveDocument.Paragraphs
If LastParaIsMyStyle Then
myParagraph.PageBreakBefore = False
With ActiveDocument.Paragraphs ' problem here
.InsertBreak Type:=wdPageBreak
End With
End If
Next
End Sub
Reply With Quote
  #2  
Old 08-19-2021, 03:38 PM
Guessed's Avatar
Guessed Guessed is online now Replace 'Page Break Before' with 'Manual Page Break' Windows 10 Replace 'Page Break Before' with 'Manual Page Break' Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,973
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This version works unless there are consecutive paragraphs with PBB (in which case only the first para gets the manual break).
Code:
Sub HarderBreaks()
  With ActiveDocument.Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .ParagraphFormat.PageBreakBefore = True
    .Text = ""
    .Replacement.Text = "^m^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
  End With
  ActiveDocument.Range.ParagraphFormat.PageBreakBefore = False
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-19-2021, 11:59 PM
Snazzy Snazzy is offline Replace 'Page Break Before' with 'Manual Page Break' Windows 10 Replace 'Page Break Before' with 'Manual Page Break' Office 2019
Novice
Replace 'Page Break Before' with 'Manual Page Break'
 
Join Date: Jun 2020
Posts: 7
Snazzy is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
This version works unless there are consecutive paragraphs with PBB (in which case only the first para gets the manual break).
Code:
Sub HarderBreaks()
  With ActiveDocument.Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .ParagraphFormat.PageBreakBefore = True
    .Text = ""
    .Replacement.Text = "^m^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
  End With
  ActiveDocument.Range.ParagraphFormat.PageBreakBefore = False
End Sub
That I how for I got with one of my previous attempts as well, as I do unfortunately have multiple PBBs. Thank you for the attempt, though.
So far I used the rather roundabout way of simply deleting all PBBs and manually inserting MPBs. But with nearly 100 pages it is tedious. So I'm hoping someone can help complete a vba code, so there is a "one-click" option.
Reply With Quote
  #4  
Old 08-20-2021, 01:21 AM
Guessed's Avatar
Guessed Guessed is online now Replace 'Page Break Before' with 'Manual Page Break' Windows 10 Replace 'Page Break Before' with 'Manual Page Break' Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,973
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this version which deals with consecutive paras as well
Code:
Sub HarderBreaks2()
  Dim aRng As Range, aPara As Paragraph
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .ParagraphFormat.PageBreakBefore = True
    .Text = ""
    '.Replacement.Text = "^m^&"
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    While .Execute
      For Each aPara In aRng.Paragraphs
        aPara.Range.InsertBefore ChrW(12)
      Next aPara
      aRng.Collapse Direction:=wdCollapseEnd
    Wend
  End With
  ActiveDocument.Range.ParagraphFormat.PageBreakBefore = False
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 08-23-2021, 02:08 AM
Snazzy Snazzy is offline Replace 'Page Break Before' with 'Manual Page Break' Windows 10 Replace 'Page Break Before' with 'Manual Page Break' Office 2019
Novice
Replace 'Page Break Before' with 'Manual Page Break'
 
Join Date: Jun 2020
Posts: 7
Snazzy is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Try this version which deals with consecutive paras as well
Code:
Sub HarderBreaks2()
  Dim aRng As Range, aPara As Paragraph
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .ParagraphFormat.PageBreakBefore = True
    .Text = ""
    '.Replacement.Text = "^m^&"
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    While .Execute
      For Each aPara In aRng.Paragraphs
        aPara.Range.InsertBefore ChrW(12)
      Next aPara
      aRng.Collapse Direction:=wdCollapseEnd
    Wend
  End With
  ActiveDocument.Range.ParagraphFormat.PageBreakBefore = False
End Sub
This first adds a MPB to all PBBs, then removes all PBBs. This way around works Thank you Guessed
Problem Solved.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace 'Page Break Before' with 'Manual Page Break' Next Page Section Break somehow changed to Cont. Section Break; each time fix spreads to prev chap Swarup Word 10 02-15-2021 06:46 PM
Replace 'Page Break Before' with 'Manual Page Break' inserting a page break after each 9th page? or skip print on the 10th page ? vender Mail Merge 2 05-27-2020 05:18 AM
Replace 'Page Break Before' with 'Manual Page Break' Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page) btse1 Word 3 11-01-2018 09:23 AM
Replace 'Page Break Before' with 'Manual Page Break' Word converts section break to page break before columns, does not insert column breaks eborda Word 1 03-24-2017 11:06 PM
Page Break is adding Blank Page when Break occurs JoannL54 Word 3 07-01-2016 05:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft