Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

retrieve current page number with vba

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
edo - 22 Sep 2006 11:37 GMT
Hi all,

can anybody tell me if it is possible to get the page number of the
active window displayed.
In other words, I don't want, with functions like
selection.information(...), retrieve the page number where the cursor
is in, because the user has maybe scrolled the document and the active
window does not contain the cursor (insertion point) at all.
The page number of the active window is for instance displayed in the
status bar, bottom left corner. Would be possible to read the page
number from the status bar?

Many thanks!
Helmut Weber - 22 Sep 2006 12:21 GMT
Hi Edo,

very approximately, for a maximized word
on a screen  1024 x 768 pixel,
and a maximized doc:

Sub Test5003()
Dim r As Range
Set r = ActiveDocument.ActiveWindow _
   .RangeFromPoint(900, 700)
   r.start = 0
   MsgBox r.Information(wdActiveEndPageNumber)
End Sub

The actual values of (900, 700) depend on so many variables
that this can only be a very weak workaround.

And note, that there can be more than one page displayed.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 22 Sep 2006 22:09 GMT
Too much redundancy in the code :-(

Sub Test5003x()
MsgBox ActiveDocument.ActiveWindow _
.RangeFromPoint(900, 700). _
Information(wdActiveEndPageNumber)
End Sub

Helmut Weber
edo - 25 Sep 2006 16:22 GMT
> Too much redundancy in the code :-(
>
[quoted text clipped - 5 lines]
>
> Helmut Weber

I really appreciate your brilliant tip. Even with the restrictions that
You listed, it works fine. There's only one annoying problem that I met
when the bottom of the page is in the active document visible. On that
time on the msgbox will appear the number 1 and the active window will
spring to page 1.
Any suggestion to by-pass the problem?

Thanks a lot
Edo
Helmut Weber - 25 Sep 2006 16:40 GMT
Hi Edo,

>I really appreciate your brilliant tip. Even with the restrictions that
>You listed, it works fine. There's only one annoying problem that I met
>when the bottom of the page is in the active document visible. On that
>time on the msgbox will appear the number 1 and the active window will
>spring to page 1.

I have no idea on how the display of a messagebox
could cause Word to goto page 1.

Sorry.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

edo - 25 Sep 2006 21:38 GMT
> Hi Edo,
>
[quoted text clipped - 16 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
edo - 25 Sep 2006 21:42 GMT
Hi Helmut,

The problem is not the msgbox itself. What I meant is that for a
strange behaviour when, let's say, the bottom of page 3 is visible on
the screen, than the message box will catch page 1 and the document
jump to page 1. Try yourself, if you can spend just a couple of
minutes, moving the active window along the page 3 till to the bottom.
There will be a point in which, from that point on, you will get 1
instead of 3, and the document will automatically spring to show page
1.

Thanks a lot again!

> Hi Edo,
>
[quoted text clipped - 16 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 25 Sep 2006 22:59 GMT
I can't reprocude that.

Maybe you start another thread and somebody
who knows better will come up with a more solid solution.

Cheers.

Helmut
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.