ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OnKey Method (https://www.excelbanter.com/excel-programming/314157-onkey-method.html)

cottage6

OnKey Method
 
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.

Tom Ogilvy

OnKey Method
 
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.

--
Regards,
Tom Ogilvy


"cottage6" wrote in message
...
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.





All times are GMT +1. The time now is 05:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com