I have a macro that scans my document for Heading 1
styles, and consequently the cursor is moved to after the last match.
I'm trying to capture the location of the cursor before this scan occurs, and then return to that position after it has finished. How do I do this?
I found this answer on SO, but it's not working (No error, it just doesn't do anything.)
Application.ScreenUpdating = False ' Turn screen updates off so the user will not know that the cursor has moved
Dim currentPosition As Long
currentPosition = Selection.Range.Start
{... do stuff here ...}
Selection.Range.Start = currentPosition
Application.ScreenUpdating = True
All you have to do is press the space bar and Word immediately returns you to the insertion point.
The easiest way to make Word jump to the last cursor position in Word documents is to use the keyboard shortcut [Shift F5].
Dim currentPosition As Range
Set currentPosition = Selection.Range 'pick up current cursor position
' do stuff — cursor gets moved around
currentPosition.Select 'return cursor to original position
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With