+ Reply to Thread
Results 1 to 2 of 2

Default Excel macro to create Menu

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    4

    Default Excel macro to create Menu

    Hi all,

    Currently I am am using below codes to create excel menu in Excel 2013.

    1. It is creating Add-ins Menu and under Add-ins menu it is creating sub menu called MyMenu with 4 command buttons

    However I want this menu in different way.

    2. I want to create this menu in line with other menu after the end of default excel menus (just like home, insert etc.) and not under add-ins menu.

    3. Further it will be easier if i can write Menu name, level, sub-level, face id etc. in any one sheet.

    Request you to help me modify code.

    Also in case you are having any other code or file, please share.
    I tried searching but could not find exactly what I am looking for.



    -----------------------------------Code------------------------------------------------
    Sub Workbook_Open()
    Dim cmbBar As CommandBar
    Dim cmbControl As CommandBarControl

    Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
    Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True) 'adds a menu item to the Menu Bar
    With cmbControl
    .Caption = "&MyMenu" 'names the menu item
    With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item
    .Caption = "Caption1" 'adds a description to the menu item
    .OnAction = "Code1" 'runs the specified macro
    .FaceId = 246 'assigns an icon to the dropdown
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "Caption2"
    .OnAction = "Code2"
    .FaceId = 246
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "Caption3"
    .OnAction = "Code3"
    .FaceId = 246
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "Caption4"
    .OnAction = "Code4"
    .FaceId = 246
    End With
    End With
    End Sub
    -----------------------------------Code------------------------------------------------
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next 'in case the menu item has already been deleted
    Application.CommandBars("Worksheet Menu Bar").Controls("MyMenu").Delete 'delete the menu item
    End Sub
    -----------------------------------Code------------------------------------------------

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Default Excel macro to create Menu

    .
    You'll need to look at XML markup language.

    There are a number of sites on the net with full instructions how to create your own
    named Menu Bar tab with sub menus.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Default Value in Excel Dropdown menu
    By davidstokes in forum Excel General
    Replies: 3
    Last Post: 01-30-2018, 06:25 AM
  2. Macro To Print to Default Printer and Create PDF
    By bigtunelover in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2016, 02:44 PM
  3. [SOLVED] Excel Context Menu - Remove all Default Controls
    By jakethepeg1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2014, 10:38 PM
  4. Replies: 0
    Last Post: 01-15-2013, 08:18 PM
  5. Create a Menu to Direct output of Macro
    By Jeff_J in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2009, 10:19 AM
  6. Replies: 2
    Last Post: 01-18-2008, 11:45 AM
  7. How do I create a macro that prints to any default printer
    By Wanna Learn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2006, 03:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1