'Trigger sub with argument with Application.OnKey if key is numerical
In Workbook.Open()
I have an Application.OnKey
for every letter on the keyboard and all the numbers.
The letters open a sub LetterPress(L as String)
Example for the letter "a":
Application.OnKey "a", "LetterPress ""a""'"
Sub LetterPress(L as string)
The sub LetterPress gets triggered.
The numbers should open a sub NumberPress(N as Integer)
.
However if I press 0 for example I get the error message (translated from Swedish)
Can't run the macro (path to macro) NumberPress "0". The macro maybe isn't available in this workbook or all macros are inactivated.
This is the code for the key "0":
Application.OnKey "0", "NumberPress ""0""'"
Application.OnKey "{96}", "NumberPress ""0""'"
In a module called "Keyboard" there's a sub:
Sub NumberPress(N as integer)
I also tried:
Sub NumberPress(N as string)
Solution 1:[1]
Looks like too many quotes:
Application.OnKey "{96}", "'NumberPress 0'"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rory |