#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
Quote:
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. |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
Quote:
Problem Solved. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page) | btse1 | Word | 3 | 11-01-2018 09:23 AM |
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 |