le_vrai_homme
New Member
- Joined
- Nov 19, 2008
- Messages
- 12
I created a custom toolbar with the following code:
I then use additional code to create it when the file is opened:
The issue is that my toolbar is disappearing when I activate another Excel file. This is especially annoying since I would like to use the toolbar command in other files while the toolbar-creation file is still open.
Any ideas?
I am using Excel 2013 on Win8.1.
Code:
Public Sub ActivateToolbar()
Dim vBar() As Variant
Dim iBar As Integer
Dim ws As Worksheet
Dim tBar As CommandBar
Dim tCtrl As CommandBarControl
Dim x As Integer
Set ws = ThisWorkbook.Worksheets("Sheet1")
vBar = ws.Range("A1").CurrentRegion.Value
Set tBar = Application.CommandBars.Add("Chart Tool", msoBarTop, False, True)
For x = 2 To UBound(vBar, 1)
Set tCtrl = tBar.Controls.Add(Type:=msoControlButton, ID:=vBar(x, 6))
tCtrl.Caption = vBar(x, 1)
tCtrl.OnAction = vBar(x, 2)
tCtrl.DescriptionText = vBar(x, 3)
tCtrl.BeginGroup = vBar(x, 4)
If IsNumeric(vBar(x, 5)) Then
tCtrl.FaceId = vBar(x, 5)
Else
ws.Shapes(vBar(x, 5)).CopyPicture
tCtrl.PasteFace
End If
Next x
tBar.Visible = True
Set ws = Nothing
Set tBar = Nothing
Set tCtrl = Nothing
End Sub
I then use additional code to create it when the file is opened:
Code:
Private Sub Workbook_Open()
Call ActivateToolbar
End Sub
The issue is that my toolbar is disappearing when I activate another Excel file. This is especially annoying since I would like to use the toolbar command in other files while the toolbar-creation file is still open.
Any ideas?
I am using Excel 2013 on Win8.1.