• Modifying the menu bar

    Author
    Topic
    #473549

    I am thinking of a new Add-In that will require a pop-up with subordinate pop-ups and command buttons to be placed in one of the existing menu bar menus at the second or third subordinate level.

    When the add-in is opened I expect to modify the existing Menu item (which may or may not have been modified by other add-ins).

    When the add-in is closed I expect to remove all of its menu items from the menu bar, recognizing that other changes may have been made to that branch of the menu bar during the time my add-in was open. There may even have been pop-ups and command buttons added to the branch which my add-in created.

    I know how to create a command bar complete with command buttons and pop-ups etc. but have no idea how to integrate this structure into an existing menu bar and later remove it in a sanitary fashion. Any guidance will be greatly appreciated. Additionally I would appreciate any insight into any existing protocol with respect to handling buttons which other programs have loaded onto a branch which you created and are about to revise or delete.

    Viewing 3 reply threads
    Author
    Replies
    • #1258387

      FWIW

      I have been advised to NOT attempt modifying existing menu bar items. They aren’t mine to modify.

    • #1258455

      In Word 2000-2003, you can build entire menus and toolbars in code using methods of the CommandBars collection. If you add them to Normal.dot, then the user may be prompted to save changes to the template, which is always annoying. If I recall correctly, there is a “temporary” parameter for new toolbars and menus which should work around that. The main problem people encounter is how to get custom icons onto the controls in this scenario. Perhaps the easiest way is to store them in the template on a non-displayed custom toolbar and then use the CopyFace and PasteFace methods to copy them from the icon storage toolbar to their ultimate locations.

      In Word 2007, custom toolbars are consigned to the Add-ins tab.

      I haven’t seen Word 2010 yet…

    • #1258471

      Don,

      Here’s an example you may find useful it uses the Temporary item mentioned by Jefferson.

      Code:
      '                         +-------------------------+             +----------+
      '-------------------------|    Application_Menu()   |-------------| 03/26/10 |
      '                         +-------------------------+             +----------+
      'Called by: Auto_Open
      'Public Variables: You should declare a public variable of type Object for
      '                  each control you create on the menu. This allows you to
      '                  easily change names and behaviours based on user actions.
      
      Sub Application_Menu()
      
         Dim oMyMenuBar As Object
         Dim oNewMenu   As Object
             
         On Error Resume Next
           Application.CommandBars("AppMenu").Delete
         On Error GoTo 0
         
         HideStdMenu
         
         Set oMyMenuBar = _
            CommandBars.Add("AppMenu", msoBarLeft + msoBarTop, , True)
         oMyMenuBar.Visible = True
         Set oNewMenu = _
            oMyMenuBar.Controls.Add(Type:=msoControlPopup, temporary:=True)
         oNewMenu.Caption = zBaseFName
      
      'Note: The PrintData menu item can be commented out forcing the user to do a
      '      PrintPreview and print from there. Could be a big paper saver!
      
         Set oCtlPrint = oNewMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)
         With oCtlPrint
             .Caption = "Print Displayed Data"
             .TooltipText = "Print currently displayed items"
             .Style = msoButtonCaption
             .OnAction = "PrintData"
         End With
         
         Set oCtlPreview = oNewMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)
         With oCtlPreview
             .Caption = "Print Preview"
             .TooltipText = "Preview Reports Before Printing"
             .Style = msoButtonCaption
             .OnAction = "CheckPrint"
         End With
      
         Set oCtlExit = oNewMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)
         With oCtlExit
             If ActiveWorkbook.ReadOnly Then
               .Caption = "Exit"
             Else
              .Caption = "Save and Exit"
             End If
             .TooltipText = "Exit the program and save data"
             .Style = msoButtonCaption
             .OnAction = "Exit_Program"
         End With
      
      
      End Sub                        'Application_Menu()

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1258517

      Thank you Jefferson and Retiree

    Viewing 3 reply threads
    Reply To: Modifying the menu bar

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: