Solved

How to scroll end of Word document close to the toolbar bottom?

Posted on 2014-09-22
14
287 Views
Last Modified: 2014-11-07
Well, how to scroll a selection/range close or at the end of the last page in a document, so that the selection/range is close to the top of the active area, i.e. below the bottom of the toolbar? Example can be seen in picture, which is a situation when spellchecker finds unknown word at the end of document and scrolls document so the word is at top.

All methods I’ve tried up to know, only manage to scroll the document so that the bottom of the last page is close down to the status bar…

I attached a picture as an example what I mean by this...
0
Comment
Question by:npaun
  • 5
  • 4
  • 2
  • +1
14 Comments
 
LVL 31

Expert Comment

by:Rob Henson
ID: 40338846
I have taken a look through various settings and can't see a User option for this function. There is a big list of layout options at the bottom of the Advanced tab in Options but none of these appear to give this as an option.

I assume it goes the way it does with the Spell Check window so that the user can see the full context of the text that the Spell Check is querying. At the end of a document, there would be a couple of options:

1) Push the Spell Check window to one side but there is still a risk that it could be covering a pertinent piece of text for the user to decide on spelling,
2) Push the document up as it does.

The fact that it does it with the Spell Check window suggests that it is possible but I suspect you would have to dig into the GUI script or write a VBA routine that forces the scroll position beyond the normal maximum.

Can I ask why you want to do this?

Thanks
Rob H
0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 40338860
Just recorded a VBA Routine to scroll to bottom of the page and got:

Sub Scroll()
    ActiveWindow.ActivePane.VerticalPercentScrolled = 62
End Sub

I can take the value at the end up to 100 but over 100 gives a Runtime error: Value out of range.
0
 

Author Comment

by:npaun
ID: 40340490
-I probably should additionally clarify my question: I meant, how to do such a scrolling programmatically, by using VBA or VB6...
-Well, I want this from a similar reason as it is used in Word spellchecker. I 'm writing a Word add-in which does some inspection of the text, and at some point it should select a word in the text... and from same reason as for the spellchecker, it is convenient that the selection is located at the top of window... this can be done for most pages, but for the last one it is a problem: for it, the bottom of the page must be scrolled upward, in the way I described
-I tested ActiveWindow.ActivePane.VerticalPercentScrolled and it cannot perform whit it takes, it can only scroll normally to the end of page, i.e. the end of page would be at the bottom, not close to the top...
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
ID: 40370547
Selection.find and selection.goto seem to work exactly like you want...
0
 

Author Comment

by:npaun
ID: 40375180
@vadimrapp1

Thank you, this looks very promising. The Selection.find looks particularly promising for my purposes. However, I have some problems in implementation. Based on  http://msdn.microsoft.com/en-us/library/office/ff839325%28v=office.15%29.aspx
I’m using the following test code

With Selection.Find
 .Forward = False
 .ClearFormatting
 .MatchWholeWord = True
 .MatchCase = False
 .Wrap = wdFindContinue
 .Execute FindText:="Microsoft"
End With

It works absolutely perfectly, if the particular word, in this example "Microsoft", is out of view, and after calling this code, the word is positioned right below the toolbar, and even if the word is at the end of the last page, just PERFECT! But, if the word (e.g. "Microsoft") is visible on the screen, then the word is just highlighted, and the page is not scrolled. I’ve been testing, and tried to work around in this way: before calling the previous code, I would scroll document for some amount so that the word goes out of view, and then calling the code, and that achieves the effect. But, to do this, I must use ScreenUpdating=False/True, and this prevents “document jumping”, but unfortunately, often, in ~10-30% of callings, use of this ScreenUpdating=False/True seems to produce some kind of a flickering, when fast black stripes shortly appear at sides of the document, which looks ugly and spoils the workaround...

Do you have some advice regarding this?
I’m using the following test code. Select a word in the text, and call the code. The document is scrolled so that the word is highlighted and positioned below the toolbar, and even if it is at the end of the last page. But, the flickering occurs sometimes. Using Word 2010.

Private Sub Command1_Click()
    Dim MyRange As Range
   
    On Error Resume Next
   
    Set MyRange = WrdDoc.Range
    Set MyRange = WrdApl.Selection.Range
   
    WrdApl.Application.ScreenUpdating = False
   
'    WrdApl.Selection.GoTo What:=wdGoToLine, Which:=wdGoToPrevious, Count:=100
    WrdApl.ActiveWindow.PageScroll True
    WrdApl.ActiveWindow.PageScroll True
   
    WrdApl.Selection.Start = MyRange.Start
    WrdApl.Selection.End = MyRange.Start

    With WrdApl.Selection.Find
        .Forward = True
        .ClearFormatting
        .MatchWholeWord = True
        .MatchCase = False
        .Wrap = wdFindContinue
        .Execute FindText:=MyRange.Text
    End With
   
    WrdApl.Application.ScreenUpdating = True
End Sub
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40375309
I would try pretty much the same, i.e. to try to scroll back and forth etc. If it flickers, well...

But, I have a revolutionary suggestion. When Microsoft developers were making their decision, how Word should react when it finds the text, and they decided that if the target is already on the screen, it's enough to highlight it, rather than scroll, maybe they had a reason to think that this is in fact optimal¹? And also, if you look at other applications, for instance the web browser you are looking at, you will see that they behave in the same way: right now when you read it, press ctrl-F, search for this very phrase, and you will see that the browser behaves in the same way as Word. Any browser. So maybe, for the purposes of consistent user experience, it's better to leave it the way it has been for the last 20 years.

¹) Microsoft spends very serious money on all kinds of grants to the universities on the research of UI. Always did. So it's possible that the decision not to scroll when it's on the page was in fact the result of a study by someone with world-known name, 40 years ago.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:npaun
ID: 40375502
Well, the problem “How to scroll end of Word document close to the toolbar bottom” is actually a part (and a side effect) of a larger problem I must solve... What I actually need is how to scroll a range/selection so it is always shown a the same place in the Word i.e. below the toolbar. I have found a way how to approximately do that, but it doesn’t work when a range/selection is close to the end of the last page, hence my current question. The current approach does help for scrolling, but on the other hand has its own drawbacks which probably make it a half-solution...
You are right when you say, one should stick to a widely accepted interface behaviors. The behavior of the search function is quite logical, and should be adhered, I agree. But, I don’t need a search behavior; I need a way to scroll a selection so that the selection is positioned always at approximately the same place, below the toolbar, always, regardless to where the selection is, beginning, middle or end of page... When you use Word spellchecker, you’ll notice that when an unknown word is found, it is selected and the document is scrolled so that selected word is located approx. three rows bellow the toolbar, and that is exactly what I need to replicate.. And the Find method is just a method you’ve suggested, and it works only partially, for my purposes, as a workaround; so if I don’t  have a complete solution for my problem, I have to find a way to amend your suggested solution...
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40375735
Here's one way to do it:  
Application.ScreenUpdating = False
    s = "the text to look for"

    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = s
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    
    Dim x As Long, pTop1 As Long, pTop2 As Long
    ActiveWindow.GetPoint x, pTop1, x, x, Selection.Range

    Const WantedSelectionPosition = 200 ' <---- specify where you want the selection
    
    If pTop1 > WantedSelectionPosition Then
        ActiveWindow.SmallScroll 1 ' experiment to find out movement per 1 smallscroll
        ActiveWindow.GetPoint x, pTop2, x, x, Selection.Range
        If pTop2 > WantedSelectionPosition Then
            decrement = Abs(pTop2 - pTop1)              ' movement achieved by one SmallScroll
            ActiveWindow.SmallScroll CInt((pTop2 - WantedSelectionPosition) / decrement)
        End If
    End If
    
    Application.ScreenUpdating = True

Open in new window


The above code calculates the needed scroll by making one "experimental" smallscroll and seeing by how much the screen moved, assuming that it may depend on monitor resolution etc. Chances are, this is not needed, and it always moves by 10, then you can do it without "the experiment", in one operation.
0
 

Author Comment

by:npaun
ID: 40378582
Thanks! I will see how to best combine these suggestions...

For the end, do you know why Selection.GoTo can only scroll page only to some extent, and no further? For instance, if a page is filed with some text, the line

WrdApl.Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1

can only scroll page until 8 rows of text (12pt Times New Roman) are visible bellow the toolbar, and cannot scroll the  last row closer to the toolbar... Is there a way to scroll a page more (by using Selection.GoTo) so that only one or two rows bellow the toolbar are visible?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40380177
> Is there a way to scroll a page mor

You probably can do it by using the same activewindow.smallscroll as in my code.
0
 

Author Comment

by:npaun
ID: 40380731
Unfortunately not: when the the page is scrolled by GoTo so that the end of document is above the status bar, the scroll bars (and hence smallscroll ) cannot scroll the page more in the Up direction...
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40429502
I've requested that this question be closed as follows:

Accepted answer: 500 points for vadimrapp1's comment #a40370547

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now