ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   shortcut for menu (https://www.excelbanter.com/excel-programming/272841-shortcut-menu.html)

Douvid

shortcut for menu
 
HI,
in the following code I create a custom menu but I would
like to have the shortcut to be set for the button and
written in the menu. I can't find where to put them ?
Can someone advise, thanks a lot


Dim cbar As Office.CommandBar
Dim monoutil As CommandBarControl
Dim menu1, cbctl1, cbctl2, cbctl3, cbctl4 As
CommandBarControl
Dim sub1, sub2, sub3 As CommandBarButton

'create a control popup on the main Worksheet menu bar
Set monoutil = Application.CommandBars("worksheet menu
bar").Controls.Add(Type:=msoControlPopup)
monoutil.Caption = "&Sbops-Tool 1.0"
monoutil.Visible = True

'add a menu item
Set cbctl1 = monoutil.Controls.Add(Type:=msoControlButton)
With cbctl1
.Visible = True
.Style = msoButtonIconAndCaption
.Caption = "Create an import File" ' is required
for caption
.OnAction = ThisWorkbook.Name & "!
outils.importfile" 'action to perform
.FaceId = 2670
End With


Bernie Deitrick[_2_]

shortcut for menu
 
Douvid,

I don't think the control's property that shows the shortcut is exposed to VBA.

But you could simply change your caption to include the shortcut:

..Caption = "Create an import File Ctrl-P"

HTH,
Bernie
Excel MVP


"Douvid" wrote in message ...
and where do I have to declare it ?
It still doesn't appear in the menu ?
But I'm getting close
Cheers,
Douvid


-----Original Message-----
Douvid,


If by shortcut you mean a CTRL+key combination, then

Application.MacroOptions _
Macro:= ThisWorkbook.Name & "!outils.importfile",

_
ShortcutKey:="p"

for example.

HTH,
Bernie
Excel MVP


"Douvid" wrote in message

...
HI,
in the following code I create a custom menu but I would
like to have the shortcut to be set for the button and
written in the menu. I can't find where to put them ?
Can someone advise, thanks a lot


Dim cbar As Office.CommandBar
Dim monoutil As CommandBarControl
Dim menu1, cbctl1, cbctl2, cbctl3, cbctl4 As
CommandBarControl
Dim sub1, sub2, sub3 As CommandBarButton

'create a control popup on the main Worksheet menu bar
Set monoutil = Application.CommandBars("worksheet menu
bar").Controls.Add(Type:=msoControlPopup)
monoutil.Caption = "&Sbops-Tool 1.0"
monoutil.Visible = True

'add a menu item
Set cbctl1 = monoutil.Controls.Add

(Type:=msoControlButton)
With cbctl1
.Visible = True
.Style = msoButtonIconAndCaption
.Caption = "Create an import File" ' is required
for caption
.OnAction = ThisWorkbook.Name & "!
outils.importfile" 'action to perform
.FaceId = 2670
End With



.





All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com