finding automatic page breaks

A

Andy Fish

Nice easy question for you Word programming experts :)

How can I detect where the automatic page breaks have been put in a
document?

TIA
Andy
 
H

Helmut Weber

Hi Andy,
How can I detect where the automatic page breaks have been put in a
document?

hmm...

at the start of pages, or to be more precise,
a pagebreak is there, where Word depending on paper
and printer etc. thinks, a new page has to start.

In fact, the automatic pagebreaks, IMHO,
aren't in the document at all, but calculated
at runtime.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

Andy Fish

Helmut Weber said:
Hi Andy,


hmm...

at the start of pages, or to be more precise,
a pagebreak is there, where Word depending on paper
and printer etc. thinks, a new page has to start.

In fact, the automatic pagebreaks, IMHO,
aren't in the document at all, but calculated
at runtime.

well, I can see the pages in the object model - something like

ActiveDocument.ActiveWindow.Panes(1).Pages

so I know that it does expose some information about the pages. However,
this doesn't allow me to idenfify which text is on which page.
 
H

Helmut Weber

Hi Andy,

maybe something rather simple:

Sub MacroX()
' text on page 2
Selection.GoTo what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=2
Selection.Bookmarks("\page").Select
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

Tony Jollans

Helmut is, of course, correct. Automatic page breaks do not exist anywhere
in the document, only, if at all, in Word's short-term memory.

You can go to the start of a page like this ..

Selection.GoTo wdGoToPage, 17

.. and Selection.Start will tell you where the page break between pages 16
and 17 is, for example.
 
H

Helmut Weber

Hi Andy,

which text on which page?

That's another question.

Like this, which returns the page number,
on which the start of the first occurence
of a string is to be found.
Zero if not found.

Public Function OnWhichPage(sTmp As String) As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = sTmp
If .Execute Then
rDcm.Collapse
OnWhichPage = rDcm.Information(wdActiveEndPageNumber)
Else
OnWhichPage = 0
End If
End With
End Function

Sub test09876()
MsgBox OnWhichPage("Meier")
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

Andy Fish

Thanks for your help Helmut.

To be honest I'm not sure precisely what I am asking for yet :)

my aim is to put some kind of markers in the document so that when I save it
as XML (WordProcessingML) I can see where the page breaks are when looking
in the XML document. I don't really know how to approach this yet, so I was
just fishing for general information about associating page numbers with
paragraphs.

It seems like Range.Information(wdActiveEndPageNumber) is the most likely
candidate - though it's still not ideal

Andy
 

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