Assign certain keyboard shortcut to certain macro, or clear that shortcut.
Important to know that you need to run the assigning code every time Excel is running, it will work per session.
Function AssignShortcutToMacro(MacroName, iShift, iCTRL, iALT, sChar)
' Assigns certain keyboard shortcut to macro
' To remove assignment, use AssignShortcutToNull()
' iShift, iCTRL and iAlt = 1 to use key
' sChar is 1 letter to be used as shortcut, examples:
' a, b, c, d, .... 1, 2, 3, 4 ...
' {BACKSPACE} or {BS}
' BREAK {BREAK}
' CAPS LOCK {CAPSLOCK}
' CLEAR {CLEAR}
' DELETE or DEL {DELETE} or {DEL}
' END {END}
' ENTER (numeric keypad) {ENTER}
' ENTER ~ (tilde)
' ESC {ESCAPE} or {ESC}
' HELP {HELP}
' PAGE DOWN {PGDN} PAGE UP {PGUP} HOME {HOME} INS {INSERT}
' UP ARROW {UP} DOWN ARROW {DOWN} LEFT ARROW {LEFT} RIGHT ARROW {RIGHT}
' NUM LOCK {NUMLOCK}
' RETURN {RETURN}
' SCROLL LOCK {SCROLLLOCK}
' TAB {TAB}
' F1 through F15 {F1} through {F15}
ShiftKey = ""
CTRLKey = ""
AltKey = ""
If iShift = 1 Then ShiftKey = "+"
If iCTRL = 1 Then CTRLKey = "^"
If iAlt = 1 Then AltKey = "%"
Application.OnKey ShiftKey & CTRLKey & AltKey & sChar, MacroName
' Application.OnKey "+^C", "YourMacroName"
End Function
Function AssignShortcutToNull(iShift, iCTRL, iALT, sChar)
ShiftKey = ""
CTRLKey = ""
AltKey = ""
If iShift = 1 Then ShiftKey = "+"
If iCTRL = 1 Then CTRLKey = "^"
If iAlt = 1 Then AltKey = "%"
Application.OnKey ShiftKey & CTRLKey & AltKey & sChar
' Application.OnKey "+^C", "YourMacroName"
End Function
' Assigns certain keyboard shortcut to macro
' To remove assignment, use AssignShortcutToNull()
' iShift, iCTRL and iAlt = 1 to use key
' sChar is 1 letter to be used as shortcut, examples:
' a, b, c, d, .... 1, 2, 3, 4 ...
' {BACKSPACE} or {BS}
' BREAK {BREAK}
' CAPS LOCK {CAPSLOCK}
' CLEAR {CLEAR}
' DELETE or DEL {DELETE} or {DEL}
' END {END}
' ENTER (numeric keypad) {ENTER}
' ENTER ~ (tilde)
' ESC {ESCAPE} or {ESC}
' HELP {HELP}
' PAGE DOWN {PGDN} PAGE UP {PGUP} HOME {HOME} INS {INSERT}
' UP ARROW {UP} DOWN ARROW {DOWN} LEFT ARROW {LEFT} RIGHT ARROW {RIGHT}
' NUM LOCK {NUMLOCK}
' RETURN {RETURN}
' SCROLL LOCK {SCROLLLOCK}
' TAB {TAB}
' F1 through F15 {F1} through {F15}
ShiftKey = ""
CTRLKey = ""
AltKey = ""
If iShift = 1 Then ShiftKey = "+"
If iCTRL = 1 Then CTRLKey = "^"
If iAlt = 1 Then AltKey = "%"
Application.OnKey ShiftKey & CTRLKey & AltKey & sChar, MacroName
' Application.OnKey "+^C", "YourMacroName"
End Function
Function AssignShortcutToNull(iShift, iCTRL, iALT, sChar)
ShiftKey = ""
CTRLKey = ""
AltKey = ""
If iShift = 1 Then ShiftKey = "+"
If iCTRL = 1 Then CTRLKey = "^"
If iAlt = 1 Then AltKey = "%"
Application.OnKey ShiftKey & CTRLKey & AltKey & sChar
' Application.OnKey "+^C", "YourMacroName"
End Function
MacroName, iShift, iCTRL, iALT, sChar
iShift, iCTRL, iALT, sChar
iShift, iCTRL, iALT, sChar
Views 145
Downloads 46
CodeID
DB ID