detecting page break

W

ward

Hello,

I'm trying to detect if a paragraph is preceded by a
(manual inserted) page break.
I use the .pagebreakbefore property, but it doesn't seem
to work.

If I run the following code in a new document with a few
page breaks and some text, the output for all paragraphs
is "0"

Sub test()
Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
Debug.Print p.PageBreakBefore
Next
End Sub

Anybody knows how i can detect a page break preceding a
paragraph?

thanks
Ward
 
J

Jonathan West

Hi Ward,

There are three possibilities you need to consider.

1. The paragraph formatting having Page Break Before set
2. A manually inserted page break
3. A manually inserted column break (which *migh* force a new page,
depending on whether it is within the last column of the existing page)
3. A section break

Your code only addresses the first opf these three possibilities.

To find the second, check the ASCII value of the first character of the
paragraph. If the value is 12, then you have a page break.

A column break is ASCII 14

For section breaks, you need to check slightly differently. The simplest way
is to check the SectionStart property of each section.
 
H

Helmut Weber

Hi Ward,
I don't know, that's wrong with "PageBreakBefore".
Anyway, You may try this:
Dim i As Integer
With ActiveDocument.Paragraphs
For i = 1 To .Count
If Left(.Item(i).Range, 1) = Chr$(12) Then
MsgBox "Paragraph: " & i 'starts with
End If
Next
End With
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
W

ward

-----Original Message-----
Hi Ward,
...
To find the second, check the ASCII value of the first character of the
paragraph. If the value is 12, then you have a page break.
....

Thanks Jonathan,
Got it working now!

ward
 

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