Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Regards
    Don

  2. #2
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts
    FWIW

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

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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...

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,168
    Thanks
    200
    Thanked 781 Times in 715 Posts
    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

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Jefferson and Retiree
    Regards
    Don

Posting Permissions

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