Returning to the last editing spot in Word 2007

Many Word 2007 users miss the ability to press Shift+F5 to return to the last place editing occurred in a document they open. Shift+F5 executes Word’s built-in GoBack command. It continues to work just fine in a document you’re editing, cycling among the current and last three places editing occurred. However, it does not work for a document you’ve just opened in Word 2007.

If you’re up for a little bit of very simple VBA programming, you can create the ability to automatically return to the spot where the cursor was the last time the document was saved. It works like this. When you close a document based on Normal.dotm, if you have a macro named AutoClose, that macro gets executed each time you close a document. When you open a document, if you have a macro named AutoOpen, that macro gets executed.

Note that you can set this up in other templates as well, but putting the system into the default global template—Normal.dotm—will handle most of the documents most people edit.

So, the first step is to create AutoClose (if you don’t already have an AutoClose macro), and include in it the instruction to insert a bookmark. I named this bookmark LastEdited. You could call it whatever you want. You could call it UncleFreddy or AuntPetunia. It doesn’t matter, as long as the act of setting it is contained in an AutoClose macro. The macro looks like this, at minimum:

Sub AutoClose()

    On Error Resume Next

    ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:=”LastEdited”

End Sub

 

So, each time you close a document based on the template that contains the AutoClose macro, a bookmark named LastEdited is created. I’ll bet you can see where this is going.

Each time you open a document, if the underlying template contains a macro named AutoOpen, it gets executed. So, guess what we’re going to have that AutoOpen macro do! Right! We’re going to have it take us to the LastEdited location. At a minimum, the AutoOpen macro will look like this:

Sub AutoOpen()

    On Error Resume Next

    Selection.GoTo What:=wdGoToBookmark, Name:=”LastEdited”

End Sub

 

That’s it! Creating the macros and setting the security is up to you. I said “at minimum,” because you might want your AutoOpen macro to do other things, like set the zoom at 140%, put the file location into the title bar, or fix you a cup of tea. These frills are entirely up to you.

You might be wondering what the On Error Resume Next is for. That’s there in case the macro encounters some kind of problem. The first time you open a document, for example, there will be no LastEdited bookmark. Without the error handling statement, you’d get a nastly little dialog box. Or, what happens if you’re editing a protected document and can’t create a bookmark. Same deal. The error handling statement keeps you from getting an error message.

One side effect of this system is that you will always be asked whether to save the file. That’s because inserting the bookmark is an edit. If you say No to saving changes, then the bookmark will not be saved.

So, what happens if there’s already a bookmark named LastEdited? Simple—it gets overwritten by the new one. If you think there’s some chance that there’s an unrelated bookmark named LastEdited in any of your documents, then give this one a different name… like TheInsertionPointLocationTheLastTimeThisDocumentWasSaved.

This entry was posted in Word 2007. Bookmark the permalink.

Leave a Reply