Results 1 to 3 of 3

how to add a Menu Item to the menubar in the VBE

Threaded View

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    how to add a Menu Item to the menubar in the VBE

    so searched google for info on this (found how to make menu items but not how to make a menu Name). would like it to appear after the Help menu.

    below is code to make the menu items:

    Sub AddNewVBEControls()
    
    Dim Ctrl As Office.CommandBarControl
    
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' Delete any existing controls with our Tag.
    '''''''''''''''''''''''''''''''''''''''''''''''''
    Set Ctrl = Application.VBE.CommandBars.FindControl(Tag:=C_TAG)
    Do Until Ctrl Is Nothing
        Ctrl.Delete
        Set Ctrl = Application.VBE.CommandBars.FindControl(Tag:=C_TAG)
    Loop
    
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' Delete any existing event handlers.
    '''''''''''''''''''''''''''''''''''''''''''''''''
    Do Until EventHandlers.Count = 0
        EventHandlers.Remove 1
    Loop
    
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' add the first control to the Tools menu.
    '''''''''''''''''''''''''''''''''''''''''''''''''
    Set MenuEvent = New CVBECommandHandler
    With Application.VBE.CommandBars("Menu Bar").Controls("Tools")
        Set CmdBarItem = .Controls.Add
    End With
    With CmdBarItem
        .Caption = "First Item"
        .BeginGroup = True
        .OnAction = "'" & ThisWorkbook.Name & "'!Procedure_One"
        .Tag = C_TAG
    End With
    
    Set MenuEvent.EvtHandler = Application.VBE.Events.CommandBarEvents(CmdBarItem)
    EventHandlers.Add MenuEvent
    
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' add the second control to the Tools menu.
    '''''''''''''''''''''''''''''''''''''''''''''''''
    Set MenuEvent = New CVBECommandHandler
    With Application.VBE.CommandBars("Menu Bar").Controls("Tools")
        Set CmdBarItem = .Controls.Add
    End With
    With CmdBarItem
        .Caption = "Second Item"
        .BeginGroup = False
        .OnAction = "'" & ThisWorkbook.Name & "'!Procedure_Two"
        .Tag = C_TAG
    End With
    
    Set MenuEvent.EvtHandler = Application.VBE.Events.CommandBarEvents(CmdBarItem)
    EventHandlers.Add MenuEvent
    
    End Sub
    checked out chip's site, microsoft and others

    tried this in the immediate window (with no success)

    application.CommandBars.Add "DansMenu"
    application.VBE.CommandBars.Add "DansMenu"
    application.vbe.commandbars("DansMenu").controls.add
    can someone point me in the right direction so that i can create a menu in the VB editor?
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Custom Right Click Menu and Sub-menu (disable inbuilt right click menu item)
    By analystbank in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2020, 04:27 AM
  2. Replies: 4
    Last Post: 12-31-2018, 02:42 PM
  3. How to rename a Custom Menu Item in the Menu Bar?
    By Sven in forum Excel General
    Replies: 3
    Last Post: 02-25-2008, 09:06 AM
  4. Add menu item to right-click menu
    By hermac@pandora.be in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2006, 05:35 AM
  5. Adding Sub Menu Item to Current Custom Menu
    By Renato in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2005, 08:55 PM
  6. [SOLVED] Menu items added with menu item editor in older versions
    By Michael Hoffmann in forum Excel General
    Replies: 2
    Last Post: 01-07-2005, 10:06 AM

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