What instruction can I use to go to the top of the current page? Thanks, Andy.
What instruction can I use to go to the top of the current page? Thanks, Andy.

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
<P ID="edit" class=small>(Edited by Rudi on 03-May-05 12:26. Sorry, I tested it more and it dd not move the selection correctly!)</P>Try this:
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=0, Name:=""
Regards,
Rudi
All's well that ends with an answer in WOPR!
Not very elegant, but should work:
ActiveDocument.Bookmarks("page").Select
Selection.Collapse
Jeez, thx Hans. Your reply opens a world of new capabilities for me. Only after seeing your bookmarks reference, and wondering where in the world you got a bookmark reference of "/page", did I turn to Word VBA help and discovered that there are quite a few reserved bookmarks that you can use in VBA to navigate with!!!
This is really gonna be a help in future Word coding for me!
Thanx a stack!
Regards,
Rudi
All's well that ends with an answer in WOPR!
Rudi, your code in my WordXp jumped to the next page.
This code, cunningly disguised as my own work (!) seems to stay on the same page:<pre>Public Function lngTopOfPage(rng As Range)
rng.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=rng.Information(wdActiveEndPageNumber), Name:=""
lngTopOfPage = Selection.Information(wdActiveEndPageNumber)
'Sub TESTlngTopOfPage()
' MsgBox lngTopOfPage(Selection.Range)
'End Sub
End Function
</pre>
I modified it a bit and it works with these changes:
<pre>Public Function lngTopOfPage(rng As Range)
rng.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, _
Count:=rng.Information(wdActiveEndPageNumber), _
Name:=""
lngTopOfPage = Selection.Information(wdActiveEndPageNumber)
End Function
Sub TESTlngTopOfPage()
Dim PgNo As Integer
PgNo = lngTopOfPage(Selection.Range)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=PgNo
End Sub</pre>
Thanx for the code. Now Andrew has a choice to use!! <img src=/S/yep.gif border=0 alt=yep width=15 height=15>
<img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Chris
Regards,
Rudi
All's well that ends with an answer in WOPR!
Thanks, Rudi, it took me a while to see what was wrong. We want the selection point to actually go to the top of the page, right, not just think about it ....... hah hah. Got me!
Here's a simpler (albeit goofy) approach that also works:
<pre> Set rngX = rngX.GoTo(What:=wdGoToPage, Name:="Andy")
</pre>
EDITED TO ADD: I should have noted that the Selection version of the same approach looks like this:
<pre> Selection.GoTo What:=wdGoToPage, Name:="Andy"</pre>
Andrew will have to take his pick. Somehow I believe Hans's simple solution will get the go!
I think its great to post a question and find 2 or 3 valid answers come back. Thats the great thing of this site! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
Regards,
Rudi
All's well that ends with an answer in WOPR!
Slightly more elegant:
Selection.End = ActiveDocument.Bookmarks("page").Start
ActiveWindow.ScrollIntoView Selection.Range, True
Here are a few predefined bookmarks that you don't find in any documentation anywhere:
Row (current table row)
Word (word under the insertion point)
Unfortunately, there's not Sentence bookmark...
Thanks, that's better if you actually want to see the top of the page.
Thanx Don. These bookmarks can prove VERY useful!
Cheers
Regards,
Rudi
All's well that ends with an answer in WOPR!
You can find more under 'Predefined Bookmarks' in Word's vba help too.
Cheers
Cheers,
Paul Edstein
[MS MVP - Word]
<img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Macropod.
Regards,
Rudi
All's well that ends with an answer in WOPR!