Discussion:
how do I find page breaks
(too old to reply)
Chip Orange
2004-11-08 15:51:23 UTC
Permalink
If I have a paragraph I'm working with, how can I test it's contents to see
if it has a page break, and if found, how do I remove it?

Alternatively, if I can't do it that way, how do I search for, find, and
delete a page break if I can determine that it's the one that should be
deleted?

thanks.

Chip
Helmut Weber
2004-11-08 17:04:22 UTC
Permalink
Hi,
searching for "^m" will find manual pagebreaks.
However, if you are not talking about manual pagebreaks,
there is no way, except finding out, whether the start
of a paragraph and the end of a paragraph are on different pages.
Like this:
Public Function MoreThanOnePage(oPrg As Paragraph) As Boolean
MoreThanOnePage = False
Selection.Collapse ' just in case
Dim p1 As Integer ' page 1
Dim p2 As Integer ' page 2
Dim r1 As Range ' range 1
Dim r2 As Range ' range 2
Set r1 = Selection.Paragraphs(1).Range
Set r2 = Selection.Paragraphs(1).Range
r1.Collapse
p1 = r1.Information(wdActiveEndPageNumber)
p2 = r2.Information(wdActiveEndPageNumber)
If p1 <> p2 Then
MoreThanOnePage = True
End If
End Function
'---
Sub test771()
MsgBox MoreThanOnePage(Selection.Paragraphs(1))
End Sub
---
And, you can not remove an automatic pagebreak at all,
only force the paragraph, the pagebreak is in,
to start on the next page. Which leaves the problem,
that a paragraph can span more than one page...
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Chip Orange
2004-11-09 20:43:08 UTC
Permalink
Thanks so much for your reply; I will need some time to study it to see if
it answers my particular problem.

My problem is that I have a paragraph object, and if it has a manual page
break within it, I need to delete it. Just knowing that it does isn't quite
enough.

I think your first sentence is telling me that I could use the find and
replace functionality, limit the scope to just my paragraph, and do it that
way, so that's where I will go looking.

thanks again,

Chip
Post by Helmut Weber
Hi,
searching for "^m" will find manual pagebreaks.
However, if you are not talking about manual pagebreaks,
there is no way, except finding out, whether the start
of a paragraph and the end of a paragraph are on different pages.
Public Function MoreThanOnePage(oPrg As Paragraph) As Boolean
MoreThanOnePage = False
Selection.Collapse ' just in case
Dim p1 As Integer ' page 1
Dim p2 As Integer ' page 2
Dim r1 As Range ' range 1
Dim r2 As Range ' range 2
Set r1 = Selection.Paragraphs(1).Range
Set r2 = Selection.Paragraphs(1).Range
r1.Collapse
p1 = r1.Information(wdActiveEndPageNumber)
p2 = r2.Information(wdActiveEndPageNumber)
If p1 <> p2 Then
MoreThanOnePage = True
End If
End Function
'---
Sub test771()
MsgBox MoreThanOnePage(Selection.Paragraphs(1))
End Sub
---
And, you can not remove an automatic pagebreak at all,
only force the paragraph, the pagebreak is in,
to start on the next page. Which leaves the problem,
that a paragraph can span more than one page...
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Jay Freedman
2004-11-08 17:14:06 UTC
Permalink
Post by Chip Orange
If I have a paragraph I'm working with, how can I test it's contents
to see if it has a page break, and if found, how do I remove it?
Alternatively, if I can't do it that way, how do I search for, find,
and delete a page break if I can determine that it's the one that
should be deleted?
thanks.
Chip
Hi Chip,

The following will remove any hard page breaks from the paragraph that
contains the insertion point (Selection). If there are none in that
paragraph, nothing happens. Change the assignment of the range to suit your
requirements.

Dim myRange As Range
Set myRange = Selection.Paragraphs(1).Range
With myRange.Find
.Text = "^m"
.Replacement.Text = ""
.Format = False
.Wrap = wdFindStop
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Chip Orange
2004-11-09 20:45:48 UTC
Permalink
Post by Jay Freedman
Post by Chip Orange
If I have a paragraph I'm working with, how can I test it's contents
to see if it has a page break, and if found, how do I remove it?
Alternatively, if I can't do it that way, how do I search for, find,
and delete a page break if I can determine that it's the one that
should be deleted?
thanks.
Chip
Hi Chip,
The following will remove any hard page breaks from the paragraph that
contains the insertion point (Selection). If there are none in that
paragraph, nothing happens. Change the assignment of the range to suit your
requirements.
Dim myRange As Range
Set myRange = Selection.Paragraphs(1).Range
With myRange.Find
.Text = "^m"
.Replacement.Text = ""
.Format = False
.Wrap = wdFindStop
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Thanks again Jay, just another one I owe you (hope you aren't close enough
to collect; I'm working up quite a tab!).

Chip

Loading...