projectile
Board Regular
- Joined
- Dec 14, 2007
- Messages
- 193
Hi
I have this code that creates a toolbar each time excel opens, however it is creating multiple instances of the macro toolbar in excel , see screen shot.
The items in yellow are duplicates of the ones highlighted in red. Each time I start up Excel, I think it tries to create another instance of the toolbars.
Is there anyway to initially add the toolbars when the addin is installed, and for the code not to keep adding toolbars if they exist.
Hope this makes sense.
I have this code that creates a toolbar each time excel opens, however it is creating multiple instances of the macro toolbar in excel , see screen shot.
The items in yellow are duplicates of the ones highlighted in red. Each time I start up Excel, I think it tries to create another instance of the toolbars.
Is there anyway to initially add the toolbars when the addin is installed, and for the code not to keep adding toolbars if they exist.
Hope this makes sense.
Code:
Sub SaveToolbarPos()
With CommandBars("ABC")
SaveSetting "MyUtils", "MyToolbar", "Pos", .Position
SaveSetting "MyUtils", "MyToolbar", "Top", .Top
SaveSetting "MyUtils", "MyToolbar", "Left", .Left
SaveSetting "MyUtils", "MyToolbar", "RowIndex", .RowIndex
End With
'DeleteSetting "MyUtils", "MyToolbar"
End Sub
Sub SetToolbarPos()
With CommandBars("IDModeling")
.Position = GetSetting("MyUtils", "MyToolbar", "Pos", msoBarFloating)
.Top = GetSetting("MyUtils", "MyToolbar", "Top", 1)
.Left = GetSetting("MyUtils", "MyToolbar", "Left", 1)
.RowIndex = GetSetting("MyUtils", "MyToolbar", "RowIndex", 1)
End With
End Sub
Option Explicit
Public Const ToolBarName As String = "House Bill"
'===========================================
Sub Auto_Open()
Call CreateMenubar
End Sub
'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub
'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars(ToolBarName).Delete
On Error GoTo 0
End Sub
'===========================================
Sub CreateMenubar()
Dim iCtr As Long
Dim MacNames As Variant
Dim CapNamess As Variant
Dim TipText As Variant
Call RemoveMenubar
MacNames = Array("HouseBill")
CapNamess = Array("Create EDI House Bill File")
TipText = Array("HouseBill tip")
With Application.CommandBars.Add
' .Name = ToolBarName
' .Left = 200
' .Top = 50
' .Protection = msoBarNoProtection
' .Visible = True
' .Position = msoBarFloating
For iCtr = LBound(MacNames) To UBound(MacNames)
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIconAndCaption
.FaceId = 71 + iCtr
.TooltipText = TipText(iCtr)
End With
Next iCtr
End With
End Sub