On Key press

G

Guest

I would like anytime I'm in Exel to be able to hit CRTL ALT ~ and call the
function testmsg.

Here is what I have:
Application.OnKey "^%{~}", "testmsg"

Does this look right?
I just put this in a new module but it is not picking up the key press.
Am I doing something wrong?
 
P

papou

Hello
Why not directly assign a shortcut to your macro (I presume you are talking
about a macro and NOT a function in which case it could not work) ?
But anyway, to fire your macro with this special key combination, the code
(Application.OnKey "^%{~}", "testmsg") should be placed in a "Auto_Open"
macro or in the Workbook_Open event of a personnal.xls workbook.
The personnal.xls workbook contains macros that are available whenever Excel
is open.
To do this simply, use the macro recorder and select to record it into the
"Personnal Macros Workbook" from the list choice in the macro recording
dialog box (please note the option text may vary since I am using a French
version).
Then amend the macro you've recorded:
name it Auto_Open instead of default Macro1 and paste your code.
Close Excel and Answer Yes to save changes in the Personnal.xls.

Reopen Excel and test your code.

HTH
Cordially
Pascal
 
G

Guest

If I execute a macro with that command, then it works for me, but remember to
type a tilde you have to use the shift key, so it the combination actually
comes out to be

Ctrl+Alt+Shift+~

(it may be different on your keyboard, but that is the way it is for mine.
The tilde is the uppercase character on the left side of the number row (1st
key).

Sub ABC()
Application.OnKey "^%`", "testmsg"

End Sub

maybe what you actually want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top