我有一个宏可以扫描我的文档以查找 Heading 1 样式,因此将光标移动到最后一次匹配之后。

我试图在此扫描发生之前捕获光标的位置,然后在完成后返回到该位置。我该怎么做呢?

我在 SO 上找到了 this answer,但它不起作用(没有错误,它什么也没做。)

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

最佳答案

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

关于vba - 将光标位置保存在文档中并稍后返回,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26650244/

10-10 18:49