VBA Custom Toolbar Disappears When Excel File Deactivated

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.
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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,216,744
Messages
6,132,471
Members
449,729
Latest member
davelevnt

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