Hi
I have few documents (will get some more) with 'Page Break followed by Heading 1 paragraph'. Now, how do I get rid of 'page breaks' without affecting the Heading 1 paragraph? Everytime I do anything, it *removes* the numbering from the Heading 1 paragraph. Page break also has Heading 1 style.
I have tried several different wildcard tyle find/replace but nothing seems to work. Any idea how I do this?
Thanks
Remove Pagebreak before Heading 1
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Remove Pagebreak before Heading 1
You do not have the required permissions to view the files attached to this post.
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Remove Pagebreak before Heading 1
OK. Had further inspiration and tried the following. I recorded a macro that worked fine when recorded it but the code below is not! Don't understand.
Code: Select all
Sub RemovePageBreaksBeforeHeading1()
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Normal")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = "^m"
.Replacement.Text = "xxxyyy^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.matchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Normal")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Normal")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = "xxxyyy"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.matchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Remove Pagebreak before Heading 1
You should probably omit the references to borders from the macro. Does this do what you want?
I replaced the style names with symbolic constants, so that the macro will run in other language versions of Word too.
Code: Select all
Sub RemovePageBreaksBeforeHeading1()
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading1)
.Replacement.ClearFormatting
.Replacement.Style = ActiveDocument.Styles(wdStyleNormal)
.Text = "^m"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Remove Pagebreak before Heading 1
Thanks Hans. Removing the border references fixed it.
BTW: Is there a way to remove the empty paragraph it leaves behind?
To put it another way, it possible to remove page breaks without affacting the next paragraph and *not* leaving the empty paragraph behind?
BTW: Is there a way to remove the empty paragraph it leaves behind?
To put it another way, it possible to remove page breaks without affacting the next paragraph and *not* leaving the empty paragraph behind?
-
- Panoramic Lounger
- Posts: 8225
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: Remove Pagebreak before Heading 1
Have you tried:
1) Putting the cursor in the Heading 1 paragraph
2) Setting that paragraph to 'page break before' (Format|paragraph|line & page breaks tab)
3) Selecting the page break and deleting it and any other unrequired paragraphs above the Heading 1
You will also need to make sure the style Heading 1 is not set to automatically update to reflect changes otherwise all your Heading 1 paragraphs will page break before.
Ken
1) Putting the cursor in the Heading 1 paragraph
2) Setting that paragraph to 'page break before' (Format|paragraph|line & page breaks tab)
3) Selecting the page break and deleting it and any other unrequired paragraphs above the Heading 1
You will also need to make sure the style Heading 1 is not set to automatically update to reflect changes otherwise all your Heading 1 paragraphs will page break before.
Ken