Delete all manual page breaks

Q

quartz

I need a function that will delete all manual page breaks in a document. Can
someone please post example code to do this?

Thanks much in advance.
 
G

G.G.Yagoda

With ActiveDocument.Range.Find
..Text = "^m"
..Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
 
V

Vince

This in addition too
With ActiveDocument.Range.Find
..Text = "^p"
..Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
 
D

Dave Lett

Hi Vince,

This isn't quite right. "^p" will replace every paragraph in the document
with nothing, and you will be left with a document that has only one
paragraph (i.e., the last one).

HTH,
Dave
 
Q

quartz

Thanks Dave for the warning. Do these solutions work for section breaks as
well? I tried this code, but it seems it has no effect on section breaks...

Thanks in advance.
 
D

Dave Lett

Hi quartz,

"^m" is only for manual page breaks; you can use the following to remove
manual page breaks and section breaks:

With Selection.Find
.ClearFormatting
''' replace section breaks
.Text = "^b"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
''' replace manual page breaks
.Text = "^m"
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 
V

Vince

Thanks Dave. Sorry about that Quartz.

Dave Lett said:
Hi quartz,

"^m" is only for manual page breaks; you can use the following to remove
manual page breaks and section breaks:

With Selection.Find
.ClearFormatting
''' replace section breaks
.Text = "^b"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
''' replace manual page breaks
.Text = "^m"
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 
H

Haydn

This doesn't work when Word inserts its own section breaks. How do you
delete these or stop word from inserting its own section breaks automatically?
 
K

Klaus Linke

Hi Haydn,
This doesn't work when Word inserts its own section breaks.

AFAIK, Word doesn't insert its own section breaks. Are you dealing with
master documents?
http://word.mvps.org/FAQs/General/RecoverMasterDocs.htm

Or, maybe more likely, you're thinking about page breaks defined in a style,
or applied as part of the paragraph formatting?
How do you delete these or stop word from inserting its own section breaks
automatically?

To remove the "page break before" from all paragraph style definitions:

Sub RemoveParaBreakBefore_Style()
Dim myStyle As Style
For Each myStyle In ActiveDocument.Styles
If myStyle.Type = wdStyleTypeParagraph Then
myStyle.ParagraphFormat.PageBreakBefore = False
End If
Next myStyle
End Sub


And to remove any "page breaks before" that you may have applied manually in
the paragraph format, you could use another "Find/Replace":

Sub RemoveParaBreakBefore_Para()
Selection.Find.ClearFormatting
Selection.Find.ParagraphFormat.PageBreakBefore = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.ParagraphFormat.PageBreakBefore = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top