Assign Macro to a Menu Item using code

S

Steven

I have seen .OnAction such as:
Item2Sub2.OnAction = "ShowMessage"

but

How do I "Assign Macro" to a Menu Item in code?

Thank you,

Steven
 
S

Stephen Newman

This works for me.

With Application.CommandBars("Cell").Controls.Add(Temporary:=True)
.Caption = "Your Caption" 'Name the button
.OnAction = "YourModule.YourCode" 'Point to the code you want
to run
.FaceId = 1089 'Adds an icon
End With
 
S

Steven

But it does not show up under the "Assign Macro" of the menu item. I want to
set it up to point to a macro in a different file just as if I had manually
gone to View / Toolbars / Customize and right clicked on the created Menu
Item and gone to "Assign Macro". I can attach a Macro from any file there
but I dont see how you do that from code.
 
S

Steven

My error:
on the .OnAction you can call a macro from another file just as if you did
it manually. The only difference is that you do not see the macro under the
"Assign Macro". WOW ... That just made my Friday !!!!!!
 

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