Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Mar 2002
    Location
    Sunnvyale, California, USA
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use of ScrollLeft & ScrollTop (Word 2000)

    Hi,
    I'm trying to figure out how to use ScrollLeft & ScrollTop in Word and Google has been no help. Actually I'm trying to save the current settings of the scrollbars so I can restore them after a bunch of processing and it looks like they are what I need to use? It also looks like I need to work with Multipages which are a mystery so before I try to figure them out I would like to make sure I am on the right track. Or you can just tell me how to read/set the scroll bars ;-}

    Thanks,
    Eric

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use of ScrollLeft & ScrollTop (Word 2000)

    If you want specific help, you'l have to tell us more about what you want to accomplish.

    Here is a very general description: you create a userform, but you need to put more controls on it than fit in the available space.

    One possibility is to provide a scroll bar, so that the user can scroll the userform. For instance, you set the ScrollBars property to 2 - fmScrollBarsVertical. The ScrollHeight property determines the total height (in points, 72 points = 1 inch) available to the user. So if you want the form to be efectively 5" high, you set ScrollHeight to 5*72 = 360. The ScrollTop property is the position of the top of the visible part of the form, relative to the "real" top. So if the "thumb" of the scroll bar is in its top position, ScrollTop is 0. The maximum value is best determined by dragging the thumb all the way down in design view. If you want to store the position of the scroll bar, assign ScrollTop to a variable.

    Another possibility is to put a multipage control on the userform. Each page of the multipage control can hold controls; only one page is visible at a time, so you can cram a lot of controls in a little space without confusing the user. If you want to put a control on a specific page, click that page before putting the control on the userform. By default, a multipage control has two pages; right-click the top part of the control to insert, delete, move or rename pages. The active page is indicated by the Value property of the multipage control; this is zero-based, so Value = 2 means that the 3rd page is/becomes active.

    Again, if you want specific help, provide details of what you want to accomplish.

  3. #3
    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: Use of ScrollLeft & ScrollTop (Word 2000)

    If you are saving the state of the scroll bars for the document window to return to a particular place in the document, you might want to use a bookmark instead, if that is an option.

  4. #4
    Lounger
    Join Date
    Mar 2002
    Location
    Sunnvyale, California, USA
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use of ScrollLeft & ScrollTop (Word 2000)

    Hi,
    I'm working with a plain document, not a form. I intercept a print request to hide some macrobuttons in the document and then restore them after printing. During all of this I turn off updating and I want to keep the displayed document from jumping when everything is done and the screen refreshes. I currently use a bookmark so the cursor goes back to the correct place, but the vertical position of the cursor tends to be different before and after which causes the document to jump when it updates. So (I know I am probably being too picky...) I will probably still need to use the bookmark to get the cursor back to the correct page but I would also like to adjust the scroll bar(s) to get the perfect effect...

    Thanks,
    Eric

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use of ScrollLeft & ScrollTop (Word 2000)

    ScrollLeft and ScrollTop are part of the MS Forms 2.0 Object Library; they are not properties of the toolbars in a Word window.

    The best you may be able to do is to store the value of ActiveWindow.VerticalPercentScrolled in a variable and to restore it when you're done. But since this is a whole number in the range of 0 - 100, it wil not be very accurate, especially for large documents.

  6. #6
    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: Use of ScrollLeft & ScrollTop (Word 2000)

    There are some very interesting methods (look for GetPoint) but I couldn't get anything to work. Except SendKeys:

    <pre>Sub PreservePosition()
    Dim bmk1 As Bookmark, intLine As Integer
    ' Bookmark insertion point and record top line of page
    Set bmk1 = Selection.Bookmarks.Add("COMEBACKHERE")
    ' Move insertion point to top of screen
    SendKeys "^%{PGUP}", True
    ' Store line number (for short pages, might need pg num)
    intLine = Selection.Information(wdFirstCharacterLineNumber)
    ' For testing only, get far away, top of doc
    Selection.HomeKey wdStory
    ' Now return to bookmark and reposition and reselect
    Selection.GoTo what:=wdGoToBookmark, Name:=bmk1.Name
    ' Move insertion point to top of screen
    SendKeys "^%{PGUP}", True
    ' Scroll up by line until screen matches original position
    Do While Selection.Information(wdFirstCharacterLineNumber) <> intLine
    ' Go to start of line
    Selection.HomeKey unit:=wdLine
    ' Move up one line (scrolls the screen to keep insert pt in view)
    Selection.MoveUp unit:=wdLine
    ' Safety valve... exit at top of document
    If Selection.Start < 1 Then Exit Do
    Loop
    ' Reselect original selection
    bmk1.Select
    ' Clean up objects
    Set bmk1 = Nothing
    End Sub</pre>

    When you test this, you must run it from inside Word (i.e., Alt+F8), or the keystrokes will not get sent to the document. I tested in the middle of a 3 page document. If you find problems, please post about them. They might not be fixable, but it would be useful to know the limitations. Note: this assumes that Word will always display the bookmarked position lower than it was originally. I can't be sure this is always true, but coming from the top of the document is seems to be true.

  7. #7
    Lounger
    Join Date
    Mar 2002
    Location
    Sunnvyale, California, USA
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use of ScrollLeft & ScrollTop (Word 2000)

    Hi,
    It worked mostly...about a third of the time it wouldn't get back to the right spot, by more than half a page sometimes. This was with a 20 page document. I've saved it and will try to keep playing around, will post any updates I make.

    Thanks,
    Eric

Posting Permissions

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