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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a menu item to EXCEL programmatically

Excel How To

Adding a menu item to EXCEL programmatically

by  taupirho  Posted    (Edited  )

Here's how to add a new menu item to EXCEL using VBA. The code below will create a new menu item labelled 'TEST' to the right of the current right-most item (normally the Help menu)

First of all delete the menu item if it already exists so we don't keep adding the same menu item on time after time.

For Each con In Application.CommandBars(1).Controls
If con.Caption = "TEST" Then
con.Delete
End If
Next

'
'Now add the new menu item:


With Application.CommandBars(1).Controls.Add(msoControlPopup)
.Caption = "TEST"
.OnAction = 'msgbox("You pressed the TEST menu item")"
End With


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top