Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Scrolling the window so that start of selection in near the top of the window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Conan Kelly - 16 Nov 2006 17:52 GMT
Hello all,

I have many long docs that I need to scan through to delete unnecessary stuff.  Is there a way that I can scroll the window so that
the start of the selection is near the top of the window?

Here is part of the code that I am currently using:

   Do While Selection.Find.Execute
'    Selection.Find.Execute
       'Assigns the selection starting position to a variable then collapses the selection.
       plngSelectionStart = Selection.Start
       Selection.Collapse
       'Finds and selects the end of the 2nd row of column headings then assigns its end position to a variable
       Selection.Find.Execute "     Rate  Contact^p"
       plngSelectionEnd = Selection.End
       'Selects the page & column headers and deletes them
       Selection.Start = plngSelectionStart
       Selection.End = plngSelectionEnd
       ActiveWindow.SmallScroll -10
       pmbrDeleteResponse = MsgBox("Do you want to delete this selection?", vbYesNoCancel + vbQuestion, "Delete Selection")
       If pmbrDeleteResponse = vbYes Then
           Selection.Delete
       ElseIf pmbrDeleteResponse = vbCancel Then
           Exit Sub
       Else
           Selection.Collapse 0
       End If
       'Resets the text to find back to the search string variable
       'Otherwise the DO WHILE loop would continue to look for the end of the 2nd line of column headings
       Selection.Find.Text = pstrSearchText
   Loop

I tried using "ActiveWindow.SmallScroll -10" to scroll the window down 10 lines after it selects the text I'm looking for.

The problem is sometimes the selection can be 50 lines long and after the SmallScroll, I can only see the bottom 10 line.  Or
sometime the very next block of text to find is already visible on the screen, and after it is selected, SmallScroll may kick it off
the bottom of the screen.

How can I edit this code to get the start of the selection to be scrolled to 5 lines down from the top of the window?

Signature

Thanks for any help anyone can provide,

Conan Kelly

Andrew V - 16 Nov 2006 19:03 GMT
Use the feature that, if a selection is extended via movement keys, the
scroll location will change to show the point of change.

Dim myRange1, myRange2 As Range
Set myRange1 = Selection.Range 'Full result
Selection.Collapse
Set myRange2 = Selection.Range 'Starting point of result
Selection.EndKey unit:=wdStory
myRange2.Select
Selection.MoveRight unit:=wdCharacter, Extend:=wdExtend
myRange1.Select

---

Alternatively, use Selection.Range.ComputeStatistics(wdStatisticLines).
With this code, you can determine how many lines the selection spans (or for
pages, use wdStatisticPages).  Then you can use this value to determine how
much you should scroll.

Andrew

------

> Hello all,
>
[quoted text clipped - 35 lines]
>
> How can I edit this code to get the start of the selection to be scrolled to 5 lines down from the top of the window?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.