OnKey Method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I got a response from Tom Ogilvy regarding how to assign a shortcut key to VB
code, which was to use the OnKey Method. My problem is I'm a bit dim when it
comes to methods, etc. Does the method go into a procedure of its own which
then calls the onkey procedure? Obviously, I'm really confused. Thanks for
any help I can get.
 
Sub SetAssignment()
Application.OnKey "^r", "MyMacro"
End Sub

Sub ResetAssignment()
Application.OnKey "^r"
End sub

You would have to run SetAssignment, then if you did Ctrl+r you should have
MyMacro run.

If you run ResetAssignment, Ctrl+r is set back to its default action

This is only in effect as long as Excel is open. When you do the
assignment, the workbook containing mymacro should be open.

If you want to have this assignment in effect most of the time, put the
assignment macro and the macro to execute in in your Personal.xls and in the
workbook_open event of personal.xls, call the setassignment macro.
 
Back
Top