CommandBarButtons have a ShortcutText property that you can use to list a command’s shortcut next to its menu item. The Cut menu item has Ctrl+X listed next to it.
In this example, I make a new menu with one item under it. OnKey is used to assign a keyboard shortcut and the ShortcutText property is used to communicate that to the user. Note that using the ShortcutText property does not actually establish the keyboard shortcut.
Dim cbPop As CommandBarPopup
DeleteMainMenu
Set cbPop = Application.CommandBars(1).Controls.Add(msoControlPopup)
Application.OnKey “^+C”, “Choice1”
With cbPop
.Caption = “MainMenu”
With .Controls.Add(msoControlButton)
.Caption = “Choice1”
.OnAction = “Choice1”
.ShortcutText = “Ctrl+Shift+C”
End With
End With
End Sub
And to get rid of it:
On Error Resume Next
Application.CommandBars(1).Controls(“MainMenu”).Delete
Application.OnKey “^+C”
End Sub
Another way to assign a shortcut key is through MacroOptions. It’s the same as Tools > Macro > Macros, then selecting the Option button.
I always use OnKey, but I’m not aware of any problems with this method. The “C” argument means Ctrl+Shift+C. All of the shortcuts established with MacroOptions start with Ctrl. You establish the Shift part by specifying a capital or lowercase C.
Oh god, I can’t believe I’ve never noticed that property before! So far I’ve been doing:
.Caption = “Choice1 Ctrl+Shift+C”
I feel stupid now :> Thanks for the tip!
This is all well and good…until you reach Excel 2007, where the ShortcutText property appears to be depreciated…
And why would you expect any different? Article published in 2008. So, if you have question – ask.
From where I stand experts doing great job and helped loot of people on the way.