Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Menu Click 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

How do I code for an Excel Menu Click event?

Code:
Application.CommandBars("Worksheet Menu bar").??

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
I think you will have to add a custom procedure to a built-in CommandBarButton. When the custom procedure is called you can trap it and then run the built-in procedure.
The snippet changes the OnAction event of the built-in "File/New" command to a VBA procedure. At the end of the CustomNewCmd procedure the "File/New" command button is reset to the built-in function.

Code:
Sub TrapAClick()
Application.CommandBars("Worksheet Menu Bar").Controls(1).Controls(1).OnAction = "CustomNewCmd"
End Sub

Sub CustomNewCmd()
MsgBox "The ""File Menu/New"" command was clicked"
Application.Dialogs(xlDialogNew).Show
Application.CommandBars("Worksheet Menu Bar").Controls(1).Controls(1).OnAction = ""
End Sub

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top