I want to make a number into a shortcut that can run a macro

bluezero2x

New member
Joined
May 23, 2015
Messages
6
Reaction score
0
Points
0
Basically, i want to be able to hit 1 and have a macro run. I found this code, though i dont know how to bind it to a macro.

So if i make a simple macro like;


Sub Adding()
'
' Adding Macro
'


'
ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]"
Range("D2").Select
End Sub


Then make a new module, and put in;

Sub test()
MsgBox "Hello"
End Sub

Sub Shortcut1()
Application.OnKey "1", "test"
End Sub

How do i bind the macro to this hotkey?
 
The "1" key by itself..... I don't think so, that would make entering numbers into Excel rather limited.

From the Help files:
The Key argument can specify any single key combined with ALT, CTRL, or SHIFT, or any combination of these keys.

Alt + F8 to bring up the macro dialogue
select the desired macro
click OPTIONS
 
Not if you put it on the number pad. I assume excel can puzzle out that it is a key of its own.

The macro recorder states you cant use numbers with the generic marco maker, regardless of ALT or the others. I was told i cant use the recorder anyways, i have to write code.

My task is to make a number do some random function. I appreciate your reply, but it doesnt tell me anything i dont know already.
 
I use this so far.

Sub Workbook_Open()Application.OnKey "{97}", "test"


Application.OnKey "{98}", "test2"


Application.OnKey "{99}", "Test3"


End Sub

Then

Sub test()
MsgBox "Well, finally"


End Sub
Sub test2()


Range("A1").Select


End Sub


Sub test3()
'
' Add Macro
'


'
ActiveCell.FormulaR1C1 = "A1+A2"



End Sub.

Only test3 doesnt work. I dont know the syntax to make it use macros.
 
Back
Top