retrieve current page number with vba

E

edo

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!
 
H

Helmut Weber

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.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Too much redundancy in the code :-(

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

Helmut Weber
 
E

edo

Helmut said:
Too much redundancy in the code :-(

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

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
 
H

Helmut Weber

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.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

edo

Helmut said:
Hi Edo,



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

Sorry.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

edo

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!
 
H

Helmut Weber

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
 

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