Home > Enterprise >  Can't trigger sub with argument with Application.OnKey if key is numerical
Can't trigger sub with argument with Application.OnKey if key is numerical

Time:02-23

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)

The numbers open a sub NumberPress(N as Integer)

However the numbers don't work. If I press 0 for example I get the errormessage (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've also tried: Sub NumberPress(N as string)

None of them work.

The Letters works though. Example for the letter "a":

Application.OnKey "a", "LetterPress ""a""'"

Sub LetterPress(L as string)

The sub LetterPress gets triggered just fine.

Anyone knows what might be the problem?

CodePudding user response:

Looks like too many quotes:

Application.OnKey "{96}", "'NumberPress 0'"
  • Related