Add-in tollbar

K

ku

Hi, I have created an add-in with a custom tool bar. When
changes are made to the toolbar they do not save with the
add-in. Any suggestions?
 
E

Edwin Tam

In Excel, you can attach a toolbar to a workbook, not to an add-in

From the View menu, choose Toolbars, then Customize, then Attach. Add-ins won't show up there. Therefore, you cannot attach a toolbar to an add-in there

Therefore, you need to open the original workbook of the add-in (or temporarily change the add-in back to a workbook), and attach the edited toolbar to the workbook, and save it as an add-in

If the add-in is not password protected, you can, in VBA Editor, change the IsAddIn property of the add-in to False. It'll become a workbook. Attach the toolbar to it, then, change the IsAddIn property back to True

Regards
Edwin Ta
[email protected]
http://www.vonixx.co


----- ku wrote: ----

Hi, I have created an add-in with a custom tool bar. When
changes are made to the toolbar they do not save with the
add-in. Any suggestions
 
A

Andrew

Toolbars are saved with the users application so that you can
customise your set-up without it being altered every time you open a
spreadsheet from someone else who had a different toolbar setup. You
can, however, get your add-in to create a toolbar when it opens (if it
doesn't already exist). The following should help if this is what you
want to do.

Goodluck,
Andrew

Public Sub CreateDefaultToolbars()
On Error Resume Next 'since toolbar will likely already exist
CreateToolbar "CstmMenu1", Array(370, 369, 368, 1589, 1592, 385,
401, 1691)
CreateToolbar "CstmMenu1", Array(151, 146, 1699, 149, 150, 1704,
203)
End Sub

Private Sub CreateToolbar(strCBarName As String, avarCBarCtls As
Variant)
Dim cbr As CommandBar
Dim i As Integer

Set cbr = Application.CommandBars.Add(strCBarName, msoBarFloating,
, False)
For i = LBound(avarCBarCtls) To UBound(avarCBarCtls)
cbr.Controls.Add , avarCBarCtls(i)
Next
cbr.Visible = False
End Sub

'to get the IDs for the items that you want to add to your toolbar use
the
'following:
Private Sub GetCBarCtlIDs()
Dim cbr As CommandBar
Dim ctl As CommandBarControl

Set cbr = Application.CommandBars("NameOfMyToolbar")
For Each ctl In cbr.Controls
Debug.Print ctl.ID
Next
End Sub
 
B

Bob Phillips

Ku,

Was the toolbar added manually, or do you have a VBA routine to create it?
With an addin the latter is preferable, but that does mean that the code has
to be updated to updated the toolbar, not just adding new controls via
Customize.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top