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
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