Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to return to my previous point of edit with the page vertically positioned identical to its original vertical position. The Shift+F5 technique returns me to the previous point of edit, but the page I return to is vertically positioned on the screen in a somewhat random manner. In other words, if my cursor is 300 vertical pixels from the top of the document viewport, I would like to re-open my page so that the location of the cursor is still 300 vertical pixels from the top of my viewport.

The following can be used to determine the vertical position (on the screen) of my text cursor:

ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range

So the challenge becomes how to scroll my document in such a manner as to return my text cursor to its original vertical position (pHeight)?

There is no corresponding ActiveWindow.SetPoint and ActiveWindow.ScrollIntoView scrolls a selection range into view, but offers no control over the vertical position of the selection range on the screen.

share|improve this question
    
for all documents or a specific one? –  Jeremy W Mar 30 '12 at 1:57
    
For a specific document –  Malcolm Mar 30 '12 at 12:11
    
Perhaps a better way to word my original question: I would like to return to my previous point of edit with the page vertically positioned identical to its original vertical position. The Shift+F5 returns me to the previous point of edit, but the page I return to is vertically positioned on the screen in a somewhat random manner. In other words, if my cursor is 300 vertical pixels from the top of the document viewport, I would like to re-open my page so that the location of the cursor is still 300 vertical pixels from the top of my viewport. –  Malcolm Mar 30 '12 at 12:17
    
That adds quite a lot of clarity. Please edit your question so that others benefit (and it receives more attention). –  Jeremy W Mar 30 '12 at 14:09
add comment

1 Answer

You may be able to accomplish this with these two macros. One to store the current view settings and another to restore them. More code help is available here and here

edit: I have updated the code to store the horizontal and vertical scroll percentages, and the current selection point in addition to the viewtype. I do not currently have a copy of Word to test this.

Store the view

Sub StoreDocView()

   ' Declare variables
   Dim OriginalViewType As Long
   Dim OriginalHorizontalScrollPercent as Long
   Dim OriginalVerticalScrollPercent as Long
   Dim OriginalSelectionStart as Long
   Dim OriginalSelectionEnd as Long

   ' Capture the current settings
   OriginalViewType = ActiveWindow.ActivePane.View.Type
   OriginalHorizontalScrollPercent = ActiveWindow.ActivePane.HorizontalPercentScrolled
   OriginalVerticalScrollPercent = ActiveWindow.ActivePane.VerticalPercentScrolled
   OriginalSelectionStart = ActiveWindow.ActivePane.Selection.Start
   OriginalSelectionEnd = ActiveWindow.ActivePane.Selection.End


   ' Store the view information to a Document Variable
   ActiveDocument.Variables.Add Name:="DocViewType", Value:=OriginalViewType
   ActiveDocument.Variables.Add Name:="DocHorizontalScroll", Value:=OriginalHorizontalScrollPercent
   ActiveDocument.Variables.Add Name:="DocVerticalScroll", Value:=OriginalVerticalScrollPercent
   ActiveDocument.Variables.Add Name:="DocSelectionStart", Value:=OriginalSelectionStart
   ActiveDocument.Variables.Add Name:="DocSelectionEnd", Value:=OriginalSelectionEnd

End Sub

Retrieve the view

Sub GetDocView()

   ' Declare variables
   Dim OriginalViewType As Long
   Dim OriginalHorizontalScrollPercent as Long
   Dim OriginalVerticalScrollPercent as Long
   Dim OriginalSelectionStart as Long
   Dim OriginalSelectionEnd as Long

   ' Get document variables
   OriginalViewType = ActiveDocument.Variables("DocViewType").Value
   OriginalHorizontalScrollPercent = ActiveDocument.Variables("DocHorizontalScroll").Value
   OriginalVerticalScrollPercent = ActiveDocument.Variables("DocVerticalScroll").Value
   OriginalSelectionStart = ActiveDocument.Variables("DocSelectionStart").Value
   OriginalSelectionEnd = ActiveDocument.Variables("DocSelectionEnd").Value

   ' Restore settings
   ActiveWindow.ActivePane.View.Type = OriginalViewType
   ActiveWindow.ActivePane.HorizontalPercentScrolled = OriginalHorizontalScrollPercent
   ActiveWindow.ActivePane.VerticalPercentScrolled = OriginalVerticalScrollPercent
   ActiveWindow.ActivePane.Selection.Start = OriginalSelectionStart
   ActiveWindow.ActivePane.Selection.End = OriginalSelectionEnd


End Sub
share|improve this answer
    
Jeremy: Thanks for your feedback. I updated the original question with more detail. Your code above preserves the viewing mode (something I hadn't thought of), but I'm looking for a way to return to a specific position on a page with the page vertically positioned in its original location. In other words, if my cursor was 300 pixels from the bottom of the toolbar, I would like to have my page vertically positioned to the identical location when I return to my previous editing position. –  Malcolm Mar 31 '12 at 17:08
    
Good catch. I added the scroll percentages and insertion point to the code –  Jeremy W Apr 3 '12 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.