Add menu and menu item buttons in Excel through VBA (add at Excel startup)

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.