从VBA立即窗口移动到代码窗口的快捷键

时间:2012-01-24 16:45:46

标签: vba keyboard-shortcuts

我知道我可以使用 Ctrl + G 将光标移动到即时窗口。是否有不同的快捷键将光标移回代码?

3 个答案:

答案 0 :(得分:9)

假设VBA在办公室; F7

答案 1 :(得分:6)

Alt + W 1

答案 2 :(得分:3)

对于那些使用AutoHotKey的人,我将Alex K的解决方案整合到我登录时运行的Autohotkey脚本中:

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability

;***  ;VBA IDE
#IfWinActive ahk_class wndclass_desked_gsk ;only execute if VBA IDE is active win
^g::   ; Ctl + g: Toggle immediate window
    WinGet, WindowUniqueID, ID, A
    ControlGetFocus, ControlID, ahk_id %WindowUniqueID%
    ControlGet, ControlHwnd, Hwnd,, %ControlID%, ahk_id %WindowUniqueID%
    ControlTextSize = 16
    VarSetCapacity(ControlText, ControlTextSize)
    SendMessage, 0xD, ControlTextSize, &ControlText,, ahk_id %ControlHWND%  ; 0xD is WM_GETTEXT.
    If (ControlText="Immediate")
        Send {F7}
    Else
        Send ^g
    Return
#IfWinActive

首先,该脚本创建一个上下文相关的 Ctl + G 热键,要求VBA IDE成为活动窗口(#IfWinActive ahk_class wndclass_desked_gsk)。

当您按 Ctl + G 时,脚本会检查当前控件的标题是否为“立即”。如果是,则发送 F7 ,将焦点发送回代码。否则重新发出 Ctl + G

相关问题