Application OnKey

crakonit

New Member
Joined
Jan 20, 2011
Messages
9
Hi All,

I have procedure that runs a macro based on a shortcut, many shortcuts in my case -works really well.

Application.OnKey "^h", "Macro1"

I'm trying to implement a CheckBox in the ribbon that tells me if the shortcuts is enabled or not, in a similar manner to "ActiveWindow.DisplayWorkbookTabs" where I can use the return of True or False status.

For the tick box to work successfully I am looking for a "is_enabled" or "shortcut_status" -How do I check when a shortcut has been assigned? Something along the lines...

if application.onkey
"^h", "Macro1" then
shortcuts_are_anabled = true
else
shortcuts_are_anabled = false
end if

But obviously this code does not work.

Other than storing a value in the spreadsheet, is there a way to check if a shortcut has been assigned?

Thanks for your help!
Eric

 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Since you already have code to assign/deassign the shortcut, just add a global variable to "remember" the status. In a standard module:
Code:
Public ControlH As Boolean

Sub AssignShortcut()
    Application.OnKey "^h", "Macro1"
    ControlH = True
End Sub

Sub DeAssignShortcut()
    Application.OnKey "^h"
    ControlH = False
End Sub

Sub Macro1()
    MsgBox "Hello World"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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