Determining if cursor is off-screen

L

Larry

How would you determine programmatically if the cursor is not in the
visible window, but scrolled off screen? I have a line of code that I
want to run only if the cursor has gotten scrolled offscreen.

Larry
 
J

Jezebel

Use the ActiveWindow.GetPoint() function, passing the Selection.Range as the
obj argument. If the returned Top is negative, the selection is off-screen
above; if it's greater than the window height, it's off-screen below.
Presumably you can check the Left value similarly, in case you're off-screen
left or right.
 
L

Larry

Jezebel,

Could you lay this out for me step by step? I'm not following you yet.

Thanks,
Larry
 
J

Jezebel

You code will be along these lines --

Dim pTop as long
Dim pLeft as long
Dim pHeight as long
Dim pWidth as long
Dim pErr as long

on error resume next
ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range
pErr = err.number
on error goto 0

if pErr <> 0 then
.... ??? off-screen in normal or outline view

else

If pTop < 0 then
.... Selection is off-screen above the current display (ie user has
scrolled DOWN from the selection)

elseif pTop > ActiveWindow.Height then
... Selection is off-screen below the current display (user has
scrolled UP)

end if

end if

This is a seriously quirky function, and I'd be very wary of it. It seems
reliably to work in Print Layout view; it fails if the selection (? or any
part of it) is off-screen in normal or outline view, but with a trappable
error.
 
L

Larry

Thanks much, but I should have mentioned that I have Word 97, and I see
that the GetPoint method does not exist in Word 97.

Larry
 
J

Jezebel

yes you should. ah well ...


Larry said:
Thanks much, but I should have mentioned that I have Word 97, and I see
that the GetPoint method does not exist in Word 97.

Larry
 
L

Larry

There still must be a simple way in VBA to determine if the cursor is
off-screen.

Larry
 
J

Jezebel

You'd think so, but it's not a conclusion you should jump to. Given that an
explicit method was added in W2000, the obvious inference is that the method
was missing in W97. Sorry I can't suggest anything better: trying
retrospecitively to determine what worked in W97 is not so easy, and *way*
beyond my failing memory.
 

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