View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_3_] Greg Wilson[_3_] is offline
external usenet poster
 
Posts: 35
Default saving toolbar buttons on custom toolbar

If you want to do it this way, I think youll have to
reconstruct the toolbar and make it invisible on close
instead of deleting it (".Visible = False"). However,
you'll probably also have to change the toolbar name as
well. I confess to not fully understanding the issue,
but, as I have it, once a toolbar with a given name is on
record in the .xlb file it will always reproduce the first
toolbar on record with this name EVEN AFTER YOU HAVE
DELETED IT !!!

Assuming you find this to be the case and if you don't
want to change the name then you can delete the .xlb file
so long as there are no other needed custom toolbars
listed on the computer. Excel will recreate it if it
cannot find it.

Preferred alternative:
I believe most professionals (I'm not one) prefer to
create their toolars on the fly to avoid complications.
A "quick and dirty" reproduction of what I do follows.
Note that the toolbar's Temporary parameter is set to True
so it will automatically delete upon closing Excel (no
code required).

'Paste to the ThisWorkbook Module:
Option Base 1
Private Sub Workbook_Open()
Call MakeToolBar
End Sub

Private Sub MakeToolBar()
Dim NewTB As CommandBar, NewBut As CommandBarButton
Dim Ar1 As Variant, Ar2 As Variant
Dim Ar3 As Variant, Ar4 As Variant
Dim i As Integer

Ar1 = Array
("Calculate", "ListNames", "DeleteBlanks", "ListOT")
Ar2 = Array(283, 222, 1786, 521)
Ar3 = Array("Calculate hours", "List names", "Delete blank
entries", "List OT hours")
Ar4 = Array("Calculates employee weekly hours", "Lists
employee names", "Deletes blank entries", "Lists total OT
hours for group")
Application.ScreenUpdating = False
Set NewTB = Application.CommandBars.Add(Name:="TestTB",
Temporary:=True)
NewTB.Visible = True
For i = 1 To 4
Set NewBut = NewTB.Controls.Add(Type:=msoControlButton)
With NewBut
.OnAction = Ar1(i)
.FaceId = Ar2(i)
.Caption = Ar3(i)
.TooltipText = Ar4(i)
.Style = msoButtonIconAndCaption
End With
Next
Application.ScreenUpdating = True
End Sub

Hope I was of some help. A reminder that I'm only a
student.

Regards,
Greg Wilson

-----Original Message-----
I've created a custom toolbar that is Attached to a

particular workbook
file. Every time I open that file, the custom toolbar

appears as it is
supposed to. However, none of the toolbar buttons that I

put on the toolbar
appear with it, even though I saved the workbook after I

put the buttons one
during the last session.

I do have some code that deletes the custom toolbar from

the workbook when
the workbook closes so the toolbar is only open when that

file is open, but
I wouldn't expect this to have any effect on whether the

toolbar buttons
remain on the toolbar. On the outside chance this is

causing my problem,
here's the code I'm using for that purpose:

***************
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("TimesheetToCalStars").Del ete
End Sub

Sub Auto_Close()
On Error Resume Next
Application.CommandBars("TimesheetToCalStars").Del ete
End Sub
***************

What can I do to get these toolbar buttons to remain on

the toolbar the next
time I open the workbook?

Thanks in advance.



.