Adding a menu selection that features a shortcut key
Sub AddMenuItem()
Dim ToolsMenu As CommandBarPopup
Dim NewMenuItem As CommandBarButton
Call DeleteMenuItem
Set ToolsMenu = CommandBars(1).FindControl(Id:=30007)
If ToolsMenu Is Nothing Then
MsgBox "Cannot add a menu item - use Ctrl+Shift+C."
Exit Sub
Else
Set NewMenuItem = ToolsMenu.Controls.Add _
(Type:=msoControlButton)
With NewMenuItem
.Caption = "&yourCaption"
.FaceId = 348
.ShortcutText = "Ctrl+Shift+C"
.OnAction = "yourAction"
.BeginGroup = True
End With
End If
Application.MacroOptions Macro:="yourMacro",HasShortcutKey:=True,ShortcutKey:="C"
End Sub
Related examples in the same category