Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard Shortcuts in Excel Menu CommandBar

The code below adds a menu item Custom1 right before New.... How can I get the keyboard shortcut assigned to CodeCustom1 (via Application.OnKey) to appear nicely right-aligned with Ctrl+N?

Sub menuItem_Create()
   With CommandBars("Worksheet menu bar").Controls("File")
      .Controls.Add(Type:=msoControlButton, Before:=1).Caption = "Custom1"
      .Controls("Custom1").OnAction = "CodeCustom1"
   End With
End Sub

enter image description here

like image 213
st12 Avatar asked Oct 05 '22 08:10

st12


1 Answers

Use the CommandbarButton's ShortcutText property:

.Controls("Custom1").ShortcutText = "ctrl+W"
like image 86
Doug Glancy Avatar answered Oct 10 '22 04:10

Doug Glancy