Consulting

Results 1 to 3 of 3

Thread: Adding and removing Excel menu buttons

  1. #1

    Adding and removing Excel menu buttons

    Hello, I have the code below that is intended to add and remove my userform button but it adds two buttons everytime excel opens. Then when I close the sheet, one goes away, the other goes away when I close the workbook.

    Any ideas?

    [vba]
    Sub Subform1()
    UserForm1.Show
    End Sub

    Sub Auto_Open()
    Dim myButton As CommandBarButton
    Set myButton = Application.CommandBars("Worksheet Menu Bar").Controls.Add
    myButton.Caption = "Dynamic"
    myButton.Tag = "Dynamic"
    myButton.Style = msoButtonIconAndCaption
    myButton.FaceId = 418
    myButton.BeginGroup = True
    myButton.OnAction = "Subform1"
    Index = myButton.Index
    End Sub
    Sub Auto_Close()
    Set myButton = CommandBars.FindControl(Type:=msoControlButton, Tag:="Dynamic")
    myButton.Delete
    End Sub
    [/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sounds like you have that code somewhere else as well.

    Post the book.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    You know what...that gave me my soloution...I was doing something stupid...I was working in the workbook that I save as an addin, with the addin installed.

Posting Permissions

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