Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving Your Place while scrolling (2000 and up)

    The following is an extremely useful tool for authors, proofreaders, and editors. It saves the current position of your cursor on the fly and then lets you go back to that same position a little later. This is a great tool if you ever have to check an in-text citation against an end-of-document bibliography and then notice that you need to change something in the bibliography. It's also good if you notice, halfway through reading a document, that an author inconsistently uses both "online" and "on-line" and want to do a quick search-and-replace without losing your place.

    It used to be that you could leave your cursor where it was, scroll up and down, and then just press one of the arrow keys to return to your position. With Word 2003, when you scroll, the cursor comes with you. This tool offers a simple workaround for that, too:
    <pre>Dim pos As Range
    Dim used As Boolean</pre>

    <pre>Sub SaveRange()
    Set pos = Selection.Range
    used = True
    End Sub</pre>

    <pre>Sub GoToRange()
    If Not used Then
    MsgBox "Nothing has been marked."
    Exit Sub
    End If
    pos.Select
    End Sub
    </pre>

    Make sure that the two Dim statement are at the very top of your module so that both of the Subs can access them. Then just add two buttons (and maybe shortcut keys) to your toolbar.

    The first macro saves the position of your cursor or any selection you've made. The second macro (re)selects the selection saved by the first macro.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Saving Your Place while scrolling (2000 and up)

    Thanks! For others reading this: using these macros is easiest if you assign them to custom toolbar buttons and/or keyboard shortcuts.

    The code can be simplified a bit: you can test pos itself to see if it has been set:
    <code>
    Dim pos As Range

    Sub SaveRange()
    Set pos = Selection.Range
    End Sub

    Sub GoToRange()
    If pos Is Nothing Then
    MsgBox "Nothing has been marked."
    Else
    pos.Select
    End If
    End Sub</code>

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Saving Your Place while scrolling (2000 and up)

    Here is a slightly fancier version that lets you toggle back and forth between two locations in a document.

    Dim pos As Range

    Sub SaveRange()
    Set pos = Selection.Range
    End Sub

    Sub GoToRange()
    Dim prevpos As Range
    If pos Is Nothing Then
    Set pos = Selection.Range
    Else
    Set prevpos = Selection.Range
    pos.Select
    Set pos = prevpos
    End If
    End Sub

  4. #4
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Your Place while scrolling (2000 and up

    Thanks to you both, I didn't even know I was missing this feature so much!

  5. #5
    Star Lounger
    Join Date
    Mar 2006
    Posts
    63
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Saving Your Place while scrolling (2000 and up)

    Hi Andy

    I use a slightly different approach, with Ctrl+Shift+T setting a temporary bookmark, and Ctrl+Shift+R returning to it. I think this has all the advantages of your approach, plus it allows you to reopen a document (even the next day) and return to the point you marked when last working on the document.

    I'm aware that pressing Shift+F5 on reopening a document works similarly, but using bookmarks is more resilient. For example:<UL><LI>they last longer (till you next press Ctrl+Shift+T); and
    <LI>they allow you to mark a position, but do one last edit at another point in the document before closing and saving.[/list]At one point I had a more sophisticated version that worked something like this (on pressing Ctrl+Shift+T):<UL><LI>If the temporary bookmark doesn't exist, create it.
    <LI>If it does, offer a choice between overwriting and creating a second one.[/list]...with similar processing for Ctrl+Shift+R.

    But in the end, I decided that was too elaborate and returned to the simpler version.

  6. #6
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Your Place while scrolling (2000 and up

    Hans

    I really like your macro - but I can only get it to work if I create it in my current document . When I create it in normal.dot, every time I run GotoRange, it spits out an error highlighting the "If pos is Nothing Then" - it's as if it isn't seeing the initial "Dim pos As Range" - which in the VB Editor appears associate with the previous macro (i.e. it has a line under it). Is there an easy way to fix this?

    Thanks & regards

    Neil

  7. #7
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving Your Place while scrolling (2000 and up

    Hans

    Please ignore my last post - I figured it out. All I had to do was place these macros first in the module, above all other macros. But I'm not sure what I will do if I install another similarly constructed macro that has the same requirements - so if you do have any good housekeeping tips for this situation, I'd still be grateful for your advice.

    Thanks again

    Neil

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Saving Your Place while scrolling (2000 and up

    The line

    Dim pos As Range

    should be at the top of the module, but the SaveRange and GoToRange macros can be anywhere in the document. Even if they are further down, the Dim pos As Range line should still be at the top, before all macros.

  9. #9
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Saving Your Place while scrolling (2000 and up)

    Thx Andyman for triggering the topic in this post. Very handy!

    David...these are a couple of very special shortcut key combinations. I have tried it out and is extremely handy. Cheers for sharing this!
    Regards,
    Rudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •