View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default AutoLoad Custom Tool Bar

Jim,

Here is a simple example. Put the code in Thisworkbook

Dim sToolbar As String

Private Sub Workbook_BeforeClose(Cancel As Boolean)

sToolbar = "MyToolbar"

On Error Resume Next
Application.CommandBars("Formatting").Controls(sTo olbar).Delete
On Error GoTo 0
End Sub

Private Sub Workbook_Open()
Dim oCB As CommandBar
Dim oCtl As CommandBarControl
Dim newMenu As Object 'CommandBarControl
Dim ctrlButton As Object 'CommandBarControl

sToolbar = "MyToolbar"

On Error Resume Next
Application.CommandBars(sToolbar).Delete
On Error GoTo 0

Set oCB = Application.CommandBars.Add(temporary:=True)

With oCB
.Name = sToolbar
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.BeginGroup = True
.Caption = "Margin Calculator"
.FaceId = 197
.Style = msoButtonIconAndCaption
.OnAction = "myMacro"
End With
.Visible = True
End With

End Sub

--

HTH

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

"Jim Carter" wrote in message
...
Can anyone help me? I am trying to get a custom toolbar to load when I

load
a specific workbook in Excel. The custom toolbar is designed and working,
but I want to autoload it when I load the specific workbook that it is

used
for. What are the VB code lines that will do this?

Also I would like to know how to close (exit) the tool bar when I close

the
specific workbook.

Thank you for your help.

Jim