Dav*_*ard 5 vba word-vba word-2010
我有一个宏来扫描我的文档的Heading 1样式,因此光标移动到最后一个匹配后.
我试图在扫描发生之前捕获光标的位置,然后在完成后返回到该位置.我该怎么做呢?
我在SO上找到了这个答案,但它没有用(没有错误,它什么也没做.)
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)