終於找到答案了 要在Workbook設定Open以及BeforeClose即會出現在自訂工具列
======================================
Private Sub Workbook_Open()
Dim myNewBar As CommandBar '宣告工具列物件
Dim myButton1 As CommandBarButton '宣告工具列按鈕物件
Dim myButton2 As CommandBarButton
Set myNewBar = Application.CommandBars.Add '新增一個工具列
myNewBar.Name = "Tool-Bar" '工具列命名
With myNewBar
Set myButton2 = .Controls.Add(msoControlButton)
============================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Tool-Bar").Delete
End Sub
With myButton2
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "Acoustic Toolbox" '顯示在工具列上的按鈕文字
.TooltipText = "ToolBox" '滑鼠移過去時,所顯示的提示文字
.FaceId = 159 '小圖示
.Tag = "MyCustomTag"
.OnAction = "ToolBox" '設定按下此鍵時所要執行的巨集
End With
.Position = msoBarTop '工具列擺放在上層
.Visible = True
End With
End Sub作者: acdx 時間: 2013-7-15 16:39
.Position = msoBarBottom 'Top '工具列擺放在上層
.Visible = True
End With
End Sub
另外還要寫一個關閉的程式
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Tool-Bar").Delete
End Sub