Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Last line visible in Window (2000/XP)

    Anybody know how to get the line number for the last line visible in the current window?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Last line visible in Window (2000/XP)

    I'm not not aware of a convenient way to set a range over the currently displayed portion of a document. The Window/Pane/View objects don't, as far as I can tell, have a precise way to identify that portion of the document. If your scenario allows for movement of the insertion point, Ctrl+Alt+PgDn (or its VBA equivalent) should locate your insertion point in the last line that fully fits (vertically) on the screen (it's a bit imprecise for tables, unfortunately, but should work for normal paragraphs). You then should be able to use the Selection.Information(wdConstantWhoseNameIDidn'tLookUp) property to get the line number.

    Okay, I recorded a macro for Ctrl+Alt+PgDn and got this:

    Selection.EndKey Unit:=wdWindow

    However, when I try to run it, I get a run-time error (4120) "bad parameter." So this is going to take further research. Good luck, and please post the solution if you find one.

  3. #3
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Last line visible in Window (2000/XP)

    I've resumed my research into this subject. So far, I've found that the wdWindow constant only seems to work with the Selection.MoveDown and Selection.MoveUp methods. I guess the macro recorder got it wrong.

    Unfortunately, for my purposes, I can't move the cursor out from under the user in order to find the last line of text in the window. One thing I'm trying to accomplish is something like this

    if the cursor is three lines from the bottom of the window then
    scroll down half a screen

    More generally, it would be nice to be able to have a LastLineInWindow() function.

    I'm going to continue looking into this, but if anybody's got further ideas, please let me know.

    Dan

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Last line visible in Window (2000/XP)

    In a somewhat similar thread on the VBA board, I used SendKeys to go to the current top line on the screen. It's not pretty or necessarily reliable, but... you might be able to borrow some of that: <post#=319047>post 319047</post#>.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •