1

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.

4
  • for all documents or a specific one?
    – Jeremy W
    Mar 30, 2012 at 1:57
  • For a specific document
    – Malcolm
    Mar 30, 2012 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, 2012 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, 2012 at 14:09

1 Answer 1

1

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
2
  • 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, 2012 at 17:08
  • Good catch. I added the scroll percentages and insertion point to the code
    – Jeremy W
    Apr 3, 2012 at 17:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .