To put your cursor in the Immediate Window, press Control+G. We all know that. To get it back to the code pane, I use Control+R, then Enter. Control+R puts the focus on the Project Explorer pane with the last active module highlighted. Enter just “opens” that module.
A few months ago, I learned on StackOverflow that F7 will take you to active code pane from the Immediate Window. Brilliant. Months later, I’m still using Control+R and Enter. Old habits…
Sounds really sad, but that has completely made my day!
It’s the only keyboard shortcut I’ve always wanted and never found and has always really irritated me. Now to get it ingrained to the muscle memory.
Simple things… =D
Thanks for the tip.
In return here is an Autohotkey script I use to get a shortcut key that open and closes the local window and closes the direct window, so you can do this with the keyboard. You will have to change the titles in WindowToClose, and also the “Send !sl” as this is for the Swedish version.
Have fun!
;Open local window
^l::
WinGetClass, WindowClass, A
If (WindowsClass=wndclass_desked_gsk)
{
Send !sl
}
Else
Send ^l
Return
;Close local window
~^+l::
WindowToClose:=”Lokalfönster”
WinGetClass, WindowClass, A
If (WindowsClass=wndclass_desked_gsk)
{
GetDesktopArea()
CoordMode, Mouse, Screen
ControlGetPos, x, y, w, h, VBAWindow1, A
If x0
{
ControlGetText, WindowText, VBAWindow1, A
If (WindowText=WindowToClose)
MouseClick, Left, MonitorWorkAreaXOrigo+x+w-10, MonitorWorkAreaYOrigo+y
}
ControlGetPos, x, y, w, h, VBAWindow2, A
If x0
{
ControlGetText, WindowText, VBAWindow2, A
If (WindowText=WindowToClose)
MouseClick, Left, MonitorWorkAreaXOrigo+x+w-10, MonitorWorkAreaYOrigo+y
}
}
Return
;Open direct window
;There is already a native key in Excel VBA IDE to do this
;Close direct window
~^+g::
WindowToClose:=”Direktfönster”
WinGetClass, WindowClass, A
If (WindowsClass=wndclass_desked_gsk)
{
GetDesktopArea()
CoordMode, Mouse, Screen
ControlGetPos, x, y, w, h, VBAWindow1, A
If x0
{
ControlGetText, WindowText, VBAWindow1, A
If (WindowText=WindowToClose)
MouseClick, Left, MonitorWorkAreaXOrigo+x+w-10, MonitorWorkAreaYOrigo+y
}
ControlGetPos, x, y, w, h, VBAWindow2, A
If x0
{
ControlGetText, WindowText, VBAWindow2, A
If (WindowText=WindowToClose)
MouseClick, Left, MonitorWorkAreaXOrigo+x+w-10, MonitorWorkAreaYOrigo+y
}
}
Return
GetDesktopArea()
{
Global
SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
MonitorWorkAreaXOrigo := MonitorWorkAreaLeft
MonitorWorkAreaYOrigo := MonitorWorkAreaTop
MonitorWorkAreaWidth := MonitorWorkAreaRight – MonitorWorkAreaXOrigo
MonitorWorkAreaHeight := MonitorWorkAreaBottom – MonitorWorkAreaYOrigo
Return
}
Good listing of VBE shortcuts at http://www.cpearson.com/excel/vbashortcutkeys.htm including the F7 one-hit wonder…
Chip also has a great list of Excel shortcuts at http://www.cpearson.com/excel/keyboardShortcuts.htm
I’ve got them both hanging off the bottom of my computer monitor.
Thanks Jeff for that listing :)
@Dick : Ctrl+R have a nice use for me when I have many project open and don’t know in which module am I. Just hit Ctrl+R and the module highlight in project list.
I also use Ctrl+F4 to close the active code window.