le_vrai_homme
New Member
- Joined
- Nov 19, 2008
- Messages
- 12
This problem must be hard because I posted it once with no replies. I'm looking for the gurus out there to take this on as a personal challenge.
The issue is that I am creating a custom toolbar in Excel with code but this toolbar disappears when another file is activated. This is bad because I want the toolbar to be used on other files while the toolbar file is open.
Here's the code but I'm not sure if this is a code issue.
I use Excel 2013 with Win 8.1.
Many thanks!
-John
The issue is that I am creating a custom toolbar in Excel with code but this toolbar disappears when another file is activated. This is bad because I want the toolbar to be used on other files while the toolbar file is open.
Here's the code but I'm not sure if this is a code issue.
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 use Excel 2013 with Win 8.1.
Many thanks!
-John