how do I find page breaks

C

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
 
H

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.
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/
 
J

Jay Freedman

Chip said:
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
 
C

Chip Orange

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
 
C

Chip Orange

Jay Freedman said:
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

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
 

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