Save the following code to the. xlam or. xla (Excel97-2003) file. In the ThisWorkBook object, add the Workbook_Open event to call the Start menu process. PrivateSubWorkbook_Open () CallMenuSetup (True) EndSub & #39 ;------------------
Save the following code to the. xlam or. xla (Excel97-2003) file. In the ThisWorkBook object, add the Workbook_Open event to call the Start menu process. Private Sub Workbook_Open () Call MenuSetup (True) End Sub 'hangzhou' add menu and menu item buttons in Excel (add when Excel starts) 'using Public Function MenuSetup (blSetUp As Boolean) dim myMenu As CommandBarPopup Dim mycontrol As CommandBarControl Dim I As Integer Dim sMenuItemName As string' the name of the function called by the Dim sMenuItemFunc As string' menu item Dim strM As St Ring 'menu name Dim strMenuItem () As string' menu item name On Error Resume next' initialize menu item ReDim strMenuItem (3, 2) 'Lower bound to VBA array starts from 1' menu item 1 strMenuItem (1, 1) = "menu item 1" strMenuItem (1, 2) = "process name of menu 1 running" 'menu item 2 strMenuItem (2, 1) = "menu item 2" strMenuItem (2, 2) = "name of the running process in Menu 2" Application. screenUpdating = false' --- add menu 1 strM = "EBS tool" Set myMenu = Application. commandBars (1 ). controls (strM) 'determines if my menu exists? If Err Then Err. clear Set myMenu = Application. commandBars (1 ). controls. add (Type: = msoControlPopup, temporary: = True) myMenu. caption = strM End If blSetUp Then '--- add menu item 1 For I = 1 To UBound (strMenuItem)' the size of the first dimension of the array sMenuItemName = strMenuItem (I, 1) sMenuItemFunc = strMenuItem (I, 2) Set mycontrol = myMenu. controls (sMenuItemName) 'determines whether the subprogram exists If Err Then Err. clear Set mycontrol = myMenu. controls. add (Type: = msoControlButton, temporary: = True) 'add a button With mycontrol at the end of the menu bar. caption = sMenuItemName 'display name of the menu item. onAction = sMenuItemFunc 'left-click the menu item button to run the process. style = msoButtonCaption: only show the text End With End If Next Else Application. commandBars (1 ). controls (strT ). delete End If Application. screenUpdating = True If Err Then Err. clearEnd FunctionPublic Sub start_App () frmSetFileSheet. show 0End Sub