Consulting

Results 1 to 9 of 9

Thread: Custom Menu Item not following document

  1. #1

    Custom Menu Item not following document

    I have created a new toolbar, added a custom menu item to it, and attached the toolbar to the workbook. Whenever I open the workbook I have the toolbar and menu items I created show up. When someone else opens the workbook the toolbar displays, but the custom menu items do not display. What do I need to do to get these to display? Thanks in advance for the help.

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    check that person's macro security settings. It's it's set to medium, they have to enable it when opening the file. If it's set to High, macros won't run at all.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Better built your toolbar on opening of the workbook. That way it won't matter because the toolbar is always built on opening (on closing you remove the toolbar). Workbook_open event use[vba]Create_Menu[/vba]and workbook_beforeclose use[vba]Delete_Menu[/vba]
    [vba]Sub Create_Menu()
    Dim MyBar As CommandBar
    Dim MyButton As CommandBarButton
    Delete_Menu
    'name of your floating bar
    Set MyBar = CommandBars.Add(Name:="Two Buttons", _
    Position:=msoBarFloating, temporary:=True)
    With MyBar
    .Top = 50
    .Left = 650
    'the two buttons that you want
    Set MyButton = .Controls.Add(Type:=msoControlButton)
    With MyButton
    .Caption = "Back to main"
    .Style = msoButtonCaption
    .BeginGroup = False
    'here you refer to the code to execute when you select this option
    'put code to execute in module (not a private one)
    .OnAction = "Macro_to_go_to_main"
    End With
    Set MyButton = .Controls.Add(Type:=msoControlButton)
    With MyButton
    .Caption = "Back to top"
    .Style = msoButtonCaption
    .BeginGroup = False
    .OnAction = "Macro_to_go_to_top"
    End With
    .Width = 150
    .Visible = True
    End With
    End Sub
    Sub Delete_Menu()
    On Error Resume Next
    'remove menu when active before activating again.
    CommandBars("Two Buttons").Delete
    On Error GoTo 0
    End Sub
    [/vba]
    Charlize

  4. #4
    Would this work with an add-in? I'm trying to put a custom menu into an add-in. Would this be the best way? Thanks!

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Yes this will work with your add-in.....as Charlize says it is the preferred method of setting up your menu..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Mentor tpoynton's Avatar
    Joined
    Feb 2005
    Location
    Clinton, MA
    Posts
    399
    Location
    not to hijack this thread (again?), but it is closely related!

    I build and delete a toolbar as indicated above (using the open and beforeclose events) with an add-in, and it does work very well! The only time I run into a problem is when I close excel, then decide that I didnt really want to close it and choose 'cancel' from the excel dialog asking if I want to save changes to the workbook. The toolbar is deleted, but the add-in is still loaded (as it should be).

    Any way to add something to the beforeclose event to rebuild the toolbar if the cancel button is clicked?

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try using the AddinInstall and AddinUninstall events.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by markpilger
    I have created a new toolbar, added a custom menu item to it, and attached the toolbar to the workbook. Whenever I open the workbook I have the toolbar and menu items I created show up. When someone else opens the workbook the toolbar displays, but the custom menu items do not display. What do I need to do to get these to display? Thanks in advance for the help.
    See if this article helps

    http://msdn.microsoft.com/archive/de...xltoolbatt.asp

  9. #9
    VBAX Mentor tpoynton's Avatar
    Joined
    Feb 2005
    Location
    Clinton, MA
    Posts
    399
    Location
    Quote Originally Posted by xld
    Try using the AddinInstall and AddinUninstall events.
    Thanks Bob! I initially had used those events; problem was that users would delete the xla, and not uninstall, the correct way, leaving the menu (most users know little about Excel). Using the beforeclose event deals with that effectively. It's not that big of a problem, but reading this thread piqued my interest! Tim

Posting Permissions

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