Shortcut Popup Menu?

R

Ricky S

How can I add my own command to the shortcut popup menu in excel? I've
copied the exsample out of the help file and when I run the macro I get this
error message.
"Invalid procedure call or argument" the code is as follows

Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
newMenu.Caption = "Custom"
Set ctrl1 = newMenu.Controls _
.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = "Import"
ctrl1.TooltipText = "Import"
ctrl1.Style = msoButtonCaption

The debuger stops at the "Ser newMenu =" line.
There must be an easy way. I just want to add my macro to the shortcut menu.
 
E

Edwin Tam

I'm not sure what you was meant by "shortcut popup menu". I assume it is the
shortcut menu when you right-click on the worksheet.

Try the following code. Copy and paste into a module, and run
"add_menu_item". You can use the same method to modify any menu. Just replace
the name of the "cell" menu with your target menu name.

'--------------------------------------
Sub add_menu_item()
With Application.CommandBars("Cell").Controls
With .Add(msoControlButton)
.Caption = "My Item"
.OnAction = "my_macro"
End With
End With
End Sub

Private Sub my_macro()
MsgBox ("Hello")
End Sub
'--------------------------------------

Regards,
Edwin Tam
(e-mail address removed)
http://www.vonixx.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top