Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't 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)

The numbers open a sub NumberPress(N as Integer)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

Looks like too many quotes:

Application.OnKey "{96}", "'NumberPress 0'"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading