如果要在宏更改窗口视图后为用户还原屏幕图像,有时可以只在宏启动时激活作为活动单元格的单元格。这并不总是成功的。

以下示例代码将还原宏启动时的窗口位置:

Dim aRow As Long, aColumn As Integer, aRange As String ' global variables

Sub RememberWindowPosition() ' run this before making changes

With ActiveWindow

aRow = .ScrollRow

aColumn = .ScrollColumn

End With

aRange = Selection.Address

End Sub

Sub RestoreWindowPosition() ' run this to restore position in the window

Range(aRange).Select

With ActiveWindow

.ScrollRow = aRow

.ScrollColumn = aColumn

End With

End Sub