Excel窗口始终在最前缘
2020-06-02 本文已影响0人
cugliming
- 新建一个工作簿,按
Alt+F11
,打开VBA编辑器。 - 单击菜单“插入→模块”,在右侧的代码窗口中粘贴下列代码:
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hwndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Sub 窗口总在最前面()
SetWindowPos Application.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub
Sub 恢复()
SetWindowPos Application.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub
- 关闭VBA编辑器
- 运行宏:
- 在Excel界面工作表界面中,按快捷键
Alt+F8
,打开“宏”对话框 -
选择宏名“窗口总在最前面”,单击“执行”按钮即可
运行宏
- 在Excel界面工作表界面中,按快捷键