Save editing place and restore when Word restarts

D

djlewis

Is there an existing add-in that will automatically save the last
place you were editing in a Word document and perhaps even take you
back there when you reopen the document?

Thanks. --David.
 
F

fumei via OfficeKB.com

Well there is not a real "add-in", but I do this all the time when I am
working on large documents.

Essentially, using the Document_Close event, I write/insert a bookmark
("StoppedHere") at the Selection (cursor). So, when the document is closed,
a bookmark is placed at the current (last) location of the cursor.

The Document_Open event simply makes the cursor - the Selection - go the that
bookmark, i.e. the last place the cursor was. It then deletes the bookmark...
so a new one will be created on the next Document_Close.

Option Explicit

Private Sub Document_Close()
ActiveDocument.Bookmarks.Add Name:="StoppedHere", _
Range:=Selection.Range
End Sub

Private Sub Document_Open()
Selection.GoTo what:=wdGoToBookmark, Name:="StoppedHere"
ActiveDocument.Bookmarks("StoppedHere").Delete
End Sub

Note: These need to be put into the ThisDocument code module.
 
D

djlewis

Well there is not a real "add-in", but I do this all the time when I am
working on large documents.

Essentially, using the Document_Close event, I write/insert a bookmark
("StoppedHere") at the Selection (cursor).  So, when the document is closed,
a bookmark is placed at the current (last) location of the cursor.

The Document_Open event simply makes the cursor - the Selection - go the that
bookmark, i.e. the last place the cursor was.  It then deletes the bookmark...
so a new one will be created on the next Document_Close.

Option Explicit

Private Sub Document_Close()
     ActiveDocument.Bookmarks.Add Name:="StoppedHere",  _
          Range:=Selection.Range
End Sub

Private Sub Document_Open()
     Selection.GoTo what:=wdGoToBookmark, Name:="StoppedHere"
     ActiveDocument.Bookmarks("StoppedHere").Delete
End Sub

Note:  These need to be put into the ThisDocument code module.

Terrific -- thank you!

Any way to make that work for all documents, automatically? I tried
putting it in normal (with an If for bookmark existence before GoTo)
but that does not work. Obviously, there is something more subtle
about it than I understand, not being very experienced in the Word
model.

Thanks. --David.
 
P

Pesach Shelnitz

There is a simple way to use macros to set the "StoppedHere" bookmark in any
file and return to it when you reopen the file using the following macros.

Sub SetStoppedHere()
If ActiveDocument.Bookmarks.Exists("StoppedHere") = False Then
ActiveDocument.Bookmarks.Add Name:="StoppedHere", _
Range:=Selection.Range
Else
ActiveDocument.Bookmarks("StoppedHere").Start = Selection.Start
ActiveDocument.Bookmarks("StoppedHere").End = Selection.End
End If
End Sub

Sub GoToStoppedHere()
If ActiveDocument.Bookmarks.Exists("StoppedHere") = True Then
ActiveDocument.Bookmarks("StoppedHere").Select
End If
End Sub

You can completely automate these macros by renaming them AutoClose and
AutoOpen, respectively, but because some security issues are associated with
macros, you may decide not to use the automated macros. If you do automate
these macros, they will work smoothly in Word 2003, but in Word 2007, you
will have to save your files with macros-enabled, and everytime you open a
file you will be prompted to agree to make macros available. If you give your
files to other folks who use Word 2007, the same prompt will appear even for
files that you created in Word 2003 or saved in the Word 2003 format, and
other users may get the impression that your files are insecure. I suggest
that you see how this works on some test files before you go for the
automated option.

Consider also that you can assign the un-automated macros to shortcut keys
and be one keystroke away from the complete automation without having to deal
with the security issues.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top