MSWord07: Macro to Save Cursor Last Location


The purpose of this article is to provide the MS Word 2007 users with the methodology to open their document to the last saved cursor position, aka, placeholder, bookmark.

Problem: When working on a multi-page document, book, report, etc..,  the author may need to temporarily save the document for editing at a later time, in which case the user executes the routine “File Save” then “FileClose”.

However, when the document is re-opened the cursor placement defaults to Page 1, Line 1, character 1.

Unfortunately, the author must then scroll down through the pages in an attempt to recall where he/she last left off before closing the document.

Of course, MSWord 2007 bookmark feature could help if you take a tangent from your concentration to manually create a bookmark before saving the document.  Then when you open the document, you could do the “GoTo” the bookmark that you created and saved.

Further, it is unclear why MSWord 2003 Shift-F5 feature was not transferred over to MSWord 2007, which is the short cut key that takes the author back to the last cursor position.

Solution: The MSWord 2007 can have its “File Save”, “FileSaveAs” and “FileOpen” features temporarily overwritten by macros so that when you click “Save”, the document will automatically create a bookmark where the cursor is and then save the document.  Then when you execute “Open”, the document will open but will also take you to the place where the bookmark was saved last.

The methodology requires the use of MSWord 2007 built-in “Developer” feature, ie VBA Macro.  And then just copying the codes below right over to the module in Word.

Note:

a) Please read all the steps first and develop a mental picture of what you will be doing.  While the steps seem tedious, they are pretty simple and you will find that the process was not as tricky as it appears.

b) The first section below are detail steps to open the programming mode in word07.

c) The next section contains 3 macros. But all 3 can be copied as one and pasted over into words visual basic window.

d) The last section is a screen shot of what my Visual Basic Window looks with the codes.  Its provided as an extra piece of help.

Procedures

Step 1: Open MSWord 2007

Step 2: Click the Office button in the upper left corner,

Step 3: Select Word Options.

Step 4: On the Popular tab, select Show Developer tab in the Ribbon.

Step 5: Close the Options,

Step 6: Click the Developer tab, and

Step 7: click Visual Basic (note: pic of visual basic screen at bottom of this article)

Step 8: Inside Visual Basic click/highlight “Normal”

Step 9: From Menu Bar, Click Insert, then click “New Module”

Step10: Highlight “New Module” in left window (double click if necessary)

Step11: Copy the entire block of codes below (between the 2 lines) with one single click and then with a single click, paste them all into the module editing window.  (See screenshot below the codes)

Step12: After copying below for Step 11, click Menu Bar, File, Save Normal. Then click close and, return to msword.  Close program, open your large document and try your new feature.

Step13: Add a new button to your toolbar and assign it with the SaveNow.  So instead of clicking the standard Save button, click on your new button that is assigned with the macro called SaveNow

VBA Codes / Macros


Sub AutoOpen()
Selection.GoTo What:=wdGoToBookmark, Name:=”OpenAt”

End Sub

Sub SaveNow()

‘ SaveNow Macro


ActiveDocument.Bookmarks(“OpenAt”).Delete
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=”OpenAt”
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveDocument.Save
ActiveDocument.Save
End Sub


Helpful Screen Shot of VB

capture

Note: In same cases, a bookmark called OpenAt may have to be manually created by you.  If so, then go to “Insert”, “BookMark” and simply add it.  (If you study the code above, you will see how/why “OpenAt” is referenced by the program codes.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s