VBA Custom Toolbar Disappears When File Deactivated

le_vrai_homme

New Member
Joined
Nov 19, 2008
Messages
12
I created a custom toolbar with the following code:

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.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,610
Messages
6,173,339
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top