How to determine if a range starts at the top of a page?

J

Jeremy

This is any page, not just the first or end page. If range is not possible is
it possible with a paragraph?
 
J

Jezebel

You can use

MyRange.Information(wdVerticalPositionRelativeToPage)

to retrieve the vertical position of the start of range. If you know the
vertical position of a range at start of page (ie, if the layout is fixed
you can work this out in advance) then simply compare with that. Or get the
vertical position of the preceding character and compare ... if it's less,
the preceding character is on the same page, and your range is therefore not
at the start --

if activedocument.Range(MyRange.Start - 1, MyRange.Start -
1).Information(wdVerticalPositionRelativeToPage) <
MyRange.Information(wdVerticalPositionRelativeToPage) then
... not at start of page


Bear in mind, this will throw an error if MyRange is at the start of
document.
 
J

Jean-Guy Marcil

Jeremy was telling us:
Jeremy nous racontait que :
This is any page, not just the first or end page. If range is not
possible is it possible with a paragraph?

You could compare the currently selected selection range.start value with
the current page range.start value:

'_______________________________________
Dim curPageRge As Range
Dim curSelRge As Range

Set curSelRge = Selection.Range

curSelRge.Collapse wdCollapseStart

Set curPageRge = curSelRge.Bookmarks("\page").Range

If curSelRge.Start = curPageRge.Start Then
MsgBox "Selection is at top of page."
Else
MsgBox "Selection is NOT at top of page."
End If
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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