I love AutoHotKey.  In this series, I'm posting some of my favorite script snippets.

Did you ever get a laptop or keyboard without a Pause/Break key?  It's one of the first keys that keyboard designers drop if they're trying to save space.  It's no big deal for most people, but for people who develop in VBA it's a huge deal.

This happened to me a few years ago, so I turned to AutoHotKey to save the day.  The script below provides another option to "break" into your VBA code.  The default shortcut is [Ctl] + [Break].  This snippet leaves that default in place, but adds an additional shortcut of [Ctl] + [CapsLock].

Even if your keyboard has a Break key, using [Ctl] + [CapsLock] may be easier on your hands than stretching to wherever it is.

The snippet is also a good example of using the #IfWinActive directive in AutoHotKey to restrict the hotkey to only working in those applications that we specify.

;***  ;MS Office programs
#IfWinActive ahk_exe EXCEL.EXE
^CapsLock::CtrlBreak   ; Use Ctrl + CapsLock to break into VBA code (for keyboards with no Break key)
#IfWinActive ahk_exe MSACCESS.EXE
^CapsLock::CtrlBreak   ; Use Ctrl + CapsLock to break into VBA code (for keyboards with no Break key)
#IfWinActive ahk_exe WINWORD.EXE
^CapsLock::CtrlBreak   ; Use Ctrl + CapsLock to break into VBA code (for keyboards with no Break key)

"Chester Bennington (Linkin Park) - I'm About to Break" by Stickman via Michael Godard Art Gallery