PDA

View Full Version : Adding and removing Excel menu buttons



impius
02-25-2009, 10:05 AM
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?


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

Bob Phillips
02-25-2009, 10:08 AM
Sounds like you have that code somewhere else as well.

Post the book.

impius
02-25-2009, 10:14 AM
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.