Automatically run a sub

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
693
Office Version
  1. 365
Platform
  1. Windows
I am trying to get a sub to run when I press a combination of letters.
This is what I use and it works fine when pressing 1 letter.
Application.OnKey "^t", "SUB_TEST"

I want to use more than 1 letter.
Possibly a letter and a number but I would settle for two letters.

Can anyone help?

Thank You
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Not tested. Does this help?

Code:
[FONT=courier new][SIZE=1][COLOR=#000000]Sub SetShortcutKeys()[/COLOR]
[COLOR=#000000]With Application[/COLOR]
[COLOR=#000000].OnKey Key:="^t", Procedure:=[/COLOR][COLOR=#333333]"SUB_TEST"[/COLOR]
[COLOR=#000000]End With[/COLOR]
[COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
 
Last edited:
Upvote 0
---EDIT---
Biz basically said the same thing :p
 
Last edited:
Upvote 0
Sorry I realized code won't answer your question. VBA help says

The Key argument can specify any single key combined with ALT, CTRL, or SHIFT, or any combination of these keys
 
Upvote 0
How can I do a CTRL,ALT & t ?

This might work.
I just need something the is more than 1 key.

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,664
Members
449,247
Latest member
wingedshoes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top