Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Adding a Macro button to the MenuBare upon opening up a file

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    245
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    i need a button (with macro attached) to show up on a user's menubar upon open/close of the worksheet.

    i once wrote similar code where a new menu item showed up on the worksheet menu bar upon open/close. i remember that the code had to be written in the 'ThisWorkbook' section of VB (NOT in a module) and that the code involved a CALL. however, beyond that, i forgot the code.

    could someone please offer a quick macro that applies a macro button (w/ macro attached) to a user's menu bar upon Open and deletes the button upon Close? thanks.



    mach3


  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    =ActiveCell.Address
    Posts
    478
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hiya,

    Here's a spot of code from one of my workbooks that adds and removes a button called Select Sample, which in turn runs a macro called StartApp. Hope this does the trick...

    Private Sub Workbook_Open()
    Dim myButton As CommandBarButton
    Set myButton = Application.CommandBars("Worksheet Menu Bar").Controls.Add
    myButton.Caption = "&Select Sample"
    myButton.Style = msoButtonCaption
    myButton.BeginGroup = True
    myButton.OnAction = "StartApp"
    End Sub

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Application.CommandBars("Worksheet Menu Bar").Controls("Select Sample").Delete
    End Sub


    P.S. You're right. Put it in Thisworkbook, not the module.


  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    245
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    bravo, thanks.

    mach3

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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