Example Adding a Menu Item to an Existing Menu

Private Sub Workbook Open() Dim lngPos As Long Dim objHelpMenu As CommandBar Dim objHelpMenuItem As CommandBarControl Dim objExcelAbout As CommandBarControl

'Get reference to Help menu

Set objHelpMenu = Application.CommandBars("Help") ' Determine position of "About Microsoft Excel"

Set objExcelAbout = objHelpMenu.Controls("About Microsoft Excel") If Not objExcelAbout Is Nothing Then lngPos = objExcelAbout.Index Else lngPos = objHelpMenu.Controls.Count End If

' Add "About SRXUtils" menu item

Set objHelpMenuItem = objHelpMenu.Controls.Add(msoControlButton,

objHelpMenuItem.Caption = "About &SRXUtils" objHelpMenuItem.BeginGroup = True objHelpMenuItem.OnAction = "ShowAboutMacros" End Sub

0 0

Post a comment