Command that puts you back to where you were in the body text after adding footnote?

New Daddy
4StarLounger
Posts: 437
Joined: 05 Nov 2012, 20:02

Command that puts you back to where you were in the body text after adding footnote?

Post by New Daddy »

I've assigned a keyboard shortcut when I need to add a footnote.
But when I need to go back up to where I was editing the main text, I either have to click the footnote number in the footnote pane or click in the body text where I want to continue.

Is there a command that will put me right back to where I was in the body text prior to entering the footnote pane?
If I can assign a keyboard shortcut to that command too, I think my footnote workflow will become really efficient.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by HansV »

There is no such command, as far as I know. See Returning to Your Document after Adding an Endnote for some workarounds, including the one you mentioned. (It works for footnotes the same way as for endnotes)
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by ChrisGreaves »

HansV wrote:
07 Jan 2023, 14:27
There is no such command, as far as I know. See Returning to Your Document after Adding an Endnote for some workarounds, including the one you mentioned. (It works for footnotes the same way as for endnotes)
@New Daddy Thanks for raising this point. I think I asked a similar question here a few years ago, but now cannot find the post.
@Hans And thanks for pointing to the Allen Wyatt article.

I note that Allen specifies Word versions 2007, 2010, 2013, 2016, 2019, but I can report that Shift+F5 works in Word2003.
Almost!

Shift+F5 returns me to the text body, but does NOT close the footnotes pane, which means the working area of my screen remains reduced.
I find it particularly annoying that the underlined "C"lose does not respond to Alt+C, which leads me to believe that the MS programmer had an early golf game that day. :evilgrin:

I have used Allen's "Save/Restore range" technique in many utility macros. Apart from that I detest workarounds that involve extra clicking or keyboard work, or that require fudges such as inserting any form of bookmark and then having to remember to remove that text.
Cheers, Chris
He who plants a seed, plants life.

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by SpeakEasy »

I'm surprised Shift-F5 works (except in a very specific set of circumstances). Although the article states "This immediately returns you to your last editing location in the main document" it actually returns you to your last editing location anywhere in the active document, - including endnotes/footnotes, etc. It is simply the keyboard equivalent of VBA's Application.GoBack (documented here)

There are some approaches using some of the built-in bookmarks (such as /PrevSel1), but they suffer some similar limitations as suffered by Application.GoBack and SHIFT-F5

So the only real solution (that I am aware of) is saving the current position and reverting to it, as the article outlines. But you don't have to add a bookmark to do that, necessarily. Although the alternative I prefer, using a publicly scoped Range variable, is pretty much the same thing:

Code: Select all

Option Explicit

Public SavedSelection As Range

Public Sub SaveLocation()
    Set SavedSelection = Selection.Range
End Sub

Public Sub GotoLastSavedLocation()
    SavedSelection.Select
End Sub
You might to then want to add a utility macro such as:

Code: Select all

Public Sub AddFootnoteSpecial()
    SaveLocation
    ActiveDocument.Footnotes.Add Selection.Range
End Sub
And then add keyboard shortcuts to it and GotoLastSavedLocation

New Daddy
4StarLounger
Posts: 437
Joined: 05 Nov 2012, 20:02

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by New Daddy »

I tried your macro, but it triggers an error.
The error message says "Run-time error '91'. Object variable or With block variable not set."
SpeakEasy wrote:
07 Jan 2023, 16:35
So the only real solution (that I am aware of) is saving the current position and reverting to it, as the article outlines. But you don't have to add a bookmark to do that, necessarily. Although the alternative I prefer, using a publicly scoped Range variable, is pretty much the same thing:

Code: Select all

Option Explicit

Public SavedSelection As Range

Public Sub SaveLocation()
    Set SavedSelection = Selection.Range
End Sub

Public Sub GotoLastSavedLocation()
    SavedSelection.Select
End Sub
You might to then want to add a utility macro such as:

Code: Select all

Public Sub AddFootnoteSpecial()
    SaveLocation
    ActiveDocument.Footnotes.Add Selection.Range
End Sub
And then add keyboard shortcuts to it and GotoLastSavedLocation

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by HansV »

The idea is that you run the AddFootnoteSpecial macro to create a footnote.
Enter the text for the footnote, then run GotoLastSavedLocation to return to the position in the body of the document where you inserted the footnote.

If you run GotoLastSavedLocation before you have run AddFootnoteSpecial (or SaveLocation), you will get error 91.

If you assign custom keyboard shortcuts to AddFootnoteSpecial and GotoLastSavedLocation (and/or custom Quick Access Toolbar buttons), you can easily invoke these macros.
Best wishes,
Hans

New Daddy
4StarLounger
Posts: 437
Joined: 05 Nov 2012, 20:02

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by New Daddy »

HansV wrote:
08 Jan 2023, 22:03
The idea is that you run the AddFootnoteSpecial macro to create a footnote.
Enter the text for the footnote, then run GotoLastSavedLocation to return to the position in the body of the document where you inserted the footnote.

If you run GotoLastSavedLocation before you have run AddFootnoteSpecial (or SaveLocation), you will get error 91.

If you assign custom keyboard shortcuts to AddFootnoteSpecial and GotoLastSavedLocation (and/or custom Quick Access Toolbar buttons), you can easily invoke these macros.
A ha! Now it works.

Small fine-tuning will make it work even better: when GotoLastSavedLocation() is invoked, it puts the cursor back in front of the footnote number in the body text. From a natural workflow perspective, you usually want the cursor right after the footnote number when you're back to the main text. Is there an easy fix?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by HansV »

Do you want to use SaveSelection and GotoLastSavedLocation only for this purpose, or do you think you'll be using it in other situations too?
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by SpeakEasy »

>want the cursor right after the footnote number

Here's one way. Just add the following procedure, and assign it custom keyboard shortcut to use instead of the shortcut to GotoLastSavedLocation

Code: Select all

Public Sub GotoLastSavedLocation2()
    GotoLastSavedLocation
    Selection.MoveRight wdWord, 2, wdMove
End Sub
This leaves you with the ability to "put[] you back to where you were in the body text after adding footnote" as per your OP, or to just after the footnote in the body text
Last edited by SpeakEasy on 09 Jan 2023, 22:05, edited 1 time in total.

New Daddy
4StarLounger
Posts: 437
Joined: 05 Nov 2012, 20:02

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by New Daddy »

HansV wrote:
09 Jan 2023, 17:24
Do you want to use SaveSelection and GotoLastSavedLocation only for this purpose, or do you think you'll be using it in other situations too?
Another good point.
People may want to use it for another purpose.
But I'll use for improved footnote workflow for now.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command that puts you back to where you were in the body text after adding footnote?

Post by HansV »

Try Speakeasy's suggestion in his latest reply.
Best wishes,
Hans