M
MichaelA
Hello All,
I have been working my way through Rod's book and have used the VBA
code to add a toolbar with a few buttons. It has worked well. Today,
I added a new button to the existing toolbar module. (In the code
below, the problem occurs with the third button.) Now the same button
is added everytime I open a mpp file leaving me with multiple buttons
for the same macro.
It doesn't happen for the other buttons, though - only the new one.
Any ideas?
thanks
Michael A.
This is my toolbar code:
Sub AddToolbar()
Dim MyBar As CommandBar
Dim MyButton As CommandBarButton
On Error Resume Next
Set MyBar = CommandBars("A-L Macros")
If MyBar Is Nothing Then
Set MyBar = CommandBars.Add(Name:="A-L Macros",
Position:=msoBarTop, Temporary:=True)
MyBar.Visible = True
End If
Set MyButton = MyBar.Controls("Excel Export")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "Excel Export"
.OnAction = "ExtractDataToExcel"
End With
End If
Set MyButton = Nothing
Set MyButton = MyBar.Controls("S-Curve")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "S-Curve"
.OnAction = "exportScurveData"
.DescriptionText = "S-Curve generated in Excel"
End With
End If
Set MyButton = Nothing
Set MyButton = MyBar.Controls("Tasks Drivers")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "Drivers"
.OnAction = "TaskDrivers"
End With
End If
End Sub
I have been working my way through Rod's book and have used the VBA
code to add a toolbar with a few buttons. It has worked well. Today,
I added a new button to the existing toolbar module. (In the code
below, the problem occurs with the third button.) Now the same button
is added everytime I open a mpp file leaving me with multiple buttons
for the same macro.
It doesn't happen for the other buttons, though - only the new one.
Any ideas?
thanks
Michael A.
This is my toolbar code:
Sub AddToolbar()
Dim MyBar As CommandBar
Dim MyButton As CommandBarButton
On Error Resume Next
Set MyBar = CommandBars("A-L Macros")
If MyBar Is Nothing Then
Set MyBar = CommandBars.Add(Name:="A-L Macros",
Position:=msoBarTop, Temporary:=True)
MyBar.Visible = True
End If
Set MyButton = MyBar.Controls("Excel Export")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "Excel Export"
.OnAction = "ExtractDataToExcel"
End With
End If
Set MyButton = Nothing
Set MyButton = MyBar.Controls("S-Curve")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "S-Curve"
.OnAction = "exportScurveData"
.DescriptionText = "S-Curve generated in Excel"
End With
End If
Set MyButton = Nothing
Set MyButton = MyBar.Controls("Tasks Drivers")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "Drivers"
.OnAction = "TaskDrivers"
End With
End If
End Sub