Macro to go back to the last location (Word 2007/10) (Chapter 1.6.3)

posted Feb 10, 2014, 3:08 PM by Wolf O'Rourc   [ updated Feb 10, 2014, 3:18 PM ]
If Application.GoBack does not work in your version of Word, you can still return to the last location you edited when you reopen the document by using a bookmark. The AutoClose macro saves the current location as a bookmark when you close a document. The AutoOpen macro then jumps to that bookmark on open. The code was developed by Edward Mendelson and published in PC Magazine at
http://www.pcmag.com/article2/0,2817,2329214,00.asp

Sub AutoClose()
On Error Resume Next
If ActiveDocument.Words.Count > 1 Then
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="LastEditPosition"
    End With
End If
End Sub

Sub AutoOpen()
On Error Resume Next
If ActiveDocument.Bookmarks.Exists("LastEditPosition") = True Then
    Selection.GoTo What:=wdGoToBookmark, Name:="LastEditPosition"
End If
End Sub

If you do not like the prompting to save the file on close, you can follow the practice of Graham Mayor and save the bookmark whenever the document is saved, as done in the following code. See the post in the Office Community at
http://answers.microsoft.com/en-us/office/forum/office_2007-word/how-to-make-word-2007-remember-last-positionpage/54299522-52f1-4b50-a4e1-c4689b3b8018

Sub FileSave()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastEditPosition"
ActiveDocument.Save
End Sub

Sub FileSaveAs()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastEditPosition"
Dialogs(wdDialogFileSaveAs).Show
End Sub
Comments