Word

Return to Last Location

Ease of Use

Intermediate

Version tested with

2002 

Submitted by:

fumei

Description:

On open of your document, you're automatically taken to the last location at which you worked. 

Discussion:

On document close, this procedure creates a new bookmark at last location of the insertion point (cursor). On document open, it returns to that bookmark. It then deletes the bookmark, so when it closes again, the new last location is marked. This is handy if you are working on large documents and just want to come back to where you left off. 

Code:

instructions for use

			

Private Sub Document_Close() ' collapse any selection to the insertion point ' there is no point in storing an extended selection as bookmark Selection.Collapse Direction:=wdCollapseStart 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

How to use:

  1. Copy the code above.
  2. Open your document in Word.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE) window.
  4. Double-click the project with your document's name.
  5. Click the plus sign beside Microsoft Word Objects.
  6. Right click ThisDocument and select View Code.
  7. Paste the code into the window that appears at right.
  8. Hit the little diskette button to save your code into the document and close the VBE window.
 

Test the code:

  1. Place selection point at whatever location you want to mark.
  2. Save and Close the document.
  3. Open the document.
 

Sample File:

StopStart.zip 4.67KB 

Approved by mdmackillop


This entry has been viewed 138 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express