# MS Word bookmark/last place you were?

**URL:** <https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744>\
**Category:** Factual Questions\
**Created:** [December 21, 2012, 3:39pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744 "2012-12-21T15:39:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [December 21, 2012, 3:39pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/1 "2012-12-21T15:39:46Z")

</div>

I believe there is a keyboard shortcut for going back to the last place you were in a document. I haven’t used it in years because it was fairly useless. As soon as you did something in another section of a document, then that became the new ‘last place’ place and you couldn’t make it back to where you were.

Here’s what I’d like to do. Run a macro that puts a placeholder, bookmark, or whatever type of field is appropriate at wherever the cursor is at the moment. Whatever it is it needs to be completely non-intrusive and cause no formatting or other changes to the document (i.e. unless you’re looking for it you’d never know it was there), and not leave any artefacts when the document goes into design (i.e. InDesign or Quark won’t translate it into a printing character). Before placing the field, the macro should also check for and delete other such fields in the document (saying “there can be only one” in its head).

Then I’d want a second macro that simply moves the cursor/view directly to that point.

Is that possible? Built in?

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [December 21, 2012, 3:53pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/2 "2012-12-21T15:53:08Z")

</div>

I don’t know if there’s something built in, but the VBA macros are simple. Here’s to add the bookmark (and delete it if it already exists):

```auto

Sub BookmarkAtCursor()
    If ActiveDocument.Bookmarks.Exists("LastCursorLoc") Then
        ActiveDocument.Bookmarks("LastCursorLoc").Delete
    End If
   
    ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastCursorLoc"
End Sub

```

And here’s to jump to it:

```auto

Sub GotoBookmark()
    If ActiveDocument.Bookmarks.Exists("LastCursorLoc") Then
        Selection.GoTo What:=wdGoToBookmark, Name:="LastCursorLoc"
    End If
End Sub

```

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [December 21, 2012, 4:04pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/3 "2012-12-21T16:04:44Z")

</div>

Wow, fantastic. Just fantastic. This is going to be extraordinarily useful! Thanks so much~  
Am I understanding this correctly–that I can add a BookmarkAtCursor\_2 macro and name the bookmark it to LastCursorLoc\_2 (and make the corresponding changes to GotoBookmark\_2) and have two different places to move back to (or as many as I can name)?

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [December 21, 2012, 4:37pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/4 "2012-12-21T16:37:32Z")

</div>

Yup, you can replicate this approach with as many bookmarks as you want.

---

<div class="post-metadata">

**Author:** ![zoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zoid/32/336_2.png) [@zoid](https://boards.straightdope.com/u/zoid)\
**Post date:** [December 21, 2012, 5:27pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/5 "2012-12-21T17:27:44Z")

</div>

Very nice - I’ll have to try that.

---

<div class="post-metadata">

**Author:** ![zoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zoid/32/336_2.png) [@zoid](https://boards.straightdope.com/u/zoid)\
**Post date:** [December 21, 2012, 5:35pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/6 "2012-12-21T17:35:06Z")

</div>

Works perfect **TroutMan**!

Now is there anyway to assign those to custom buttons?

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [December 21, 2012, 5:42pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/7 "2012-12-21T17:42:33Z")

</div>

The way you assign them will differ by Word version. For Word 2010, right-click in the ribbon and select Customize the Ribbon (or go to Word options through the File menu). On the Customize Ribbon tab, select Macros in “Choose commands from”. You can add it to a custom group on any ribbon.

At the bottom of the same screen, you can also assign keyboard shortcuts to the macros.

---

<div class="post-metadata">

**Author:** ![zoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zoid/32/336_2.png) [@zoid](https://boards.straightdope.com/u/zoid)\
**Post date:** [December 21, 2012, 5:49pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/8 "2012-12-21T17:49:17Z")

</div>

Thank you!!!

---

<div class="post-metadata">

**Author:** ![Exapno\_Mapcase](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/exapno_mapcase/32/1051_2.png) [@Exapno\_Mapcase](https://boards.straightdope.com/u/Exapno_Mapcase)\
**Post date:** [December 21, 2012, 5:51pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/9 "2012-12-21T17:51:38Z")

</div>

Just for the record, it’s Shift-F5 that takes you to Microsoft’s definition of the last place.

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [December 21, 2012, 6:13pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/10 "2012-12-21T18:13:04Z")

</div>

It’s that shift/F5 that I tried using long ago. Great if you don’t move around or do much in a document, but its utility falls off the page very quickly.

In addition to assigning macros to the keyboard and ribbon, it’s very handy to map your mouse to the macros. I’m heavily reliant on my 12-button Logitech, and have been drooling over some gaming mice with more. If you have a Logitech mouse, get [Uberoptions](http://uberoptions.net/)to go with it–it’s a fantastic program that replaces SetPoint.

---

<div class="post-metadata">

**Author:** ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)\
**Post date:** [December 21, 2012, 7:24pm UTC](https://boards.straightdope.com/t/ms-word-bookmark-last-place-you-were/644744/11 "2012-12-21T19:24:56Z")

</div>

You didn’t ask for it, but you gave me an excuse to blow off work for a little bit. Here are some updated macros that maintain a history of “last positions”, so each time the macro runs it steps back one position. I arbitrarily set it to keep a maximum number of 10 bookmarks in the history, but you can change that.

I’ve done only simple testing of this, so no guarantees.

```auto

Option Explicit
Const MAX_SAVED_BOOKMARKS = 10

Sub SetBookmarkAtCursor()
    Dim lastBookmark As Long
    
    lastBookmark = SetLastBookmarkIndex()
    
    If lastBookmark > MAX_SAVED_BOOKMARKS Then
        If ActiveDocument.Bookmarks.Exists("LastCursorLoc_" & lastBookmark - MAX_SAVED_BOOKMARKS) Then
            ActiveDocument.Bookmarks("LastCursorLoc_" & lastBookmark - MAX_SAVED_BOOKMARKS).Delete
        End If
    End If
    
    ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="LastCursorLoc_" & lastBookmark
End Sub

Sub GotoLastBookmark()
    Dim startBkmk As Long, endBkmk As Long, i As Long, jump As Boolean
    
    jump = False
    
    endBkmk = GetLastBookmarkIndex()
    i = endBkmk
    startBkmk = endBkmk - MAX_SAVED_BOOKMARKS
    If startBkmk < 2 Then startBkmk = 2
    
    Do While i > startBkmk And i > 1 And Not jump
        If ActiveDocument.Bookmarks.Exists("LastCursorLoc_" & i) Then
            If ActiveDocument.Bookmarks("\Sel").End = ActiveDocument.Bookmarks("LastCursorLoc_" & i).End Then
                If ActiveDocument.Bookmarks.Exists("LastCursorLoc_" & i - 1) Then
                    Selection.GoTo What:=wdGoToBookmark, Name:="LastCursorLoc_" & i - 1
                    jump = True
                End If
            End If
        End If
        i = i - 1
    Loop
    
    If Not jump And ActiveDocument.Bookmarks.Exists("LastCursorLoc_" & endBkmk) Then
        Selection.GoTo What:=wdGoToBookmark, Name:="LastCursorLoc_" & endBkmk
    End If
End Sub

Function SetLastBookmarkIndex() As Long
    SetLastBookmarkIndex = GetLastBookmarkIndex() + 1
    ActiveDocument.Variables("LastBookmarkIndex") = SetLastBookmarkIndex
End Function

Function GetLastBookmarkIndex() As Long
    ' no way to check if variable already exists, so add it if we get an error
    On Error Resume Next
    GetLastBookmarkIndex = ActiveDocument.Variables("LastBookmarkIndex")
        
    If Err.Number <> 0 Then
        GetLastBookmarkIndex = 0
        ActiveDocument.Variables.Add Name:="LastBookmarkIndex", Value:=GetLastBookmarkIndex
    End If
    
    On Error GoTo 0
End Function

```

I’ll also note that if you bookmark the same position twice, it short-circuits the history. I.e., if your history is A-\>B-\>C-\>D-\>B, then going back from position B will always take you to D; you won’t get back to A. I don’t feel inspired to see if I can fix that, so I’m going to say it’s an intended feature.

Let me know if you uncover any issues.
