Private Sub Workbook_BeforeClose(Cancel As Boolean)
'关闭工作簿前,删除新创建的工具条先
Dim bar_name As String
bar_name = "HRBSJ"
Application.CommandBars(bar_name).Delete
On Error GoTo Exception
Exit Sub
Exception:
End Sub
Private Sub Workbook_Open()
'打开工作簿时创建工具条
Dim bar_name As String
Dim new_bar As Office.CommandBar
bar_name = "HRBSJ"
Set new_bar = Application.CommandBars.Add(bar_name)
new_bar.Visible = True
new_bar.Position = msoBarLeft
With new_bar.Controls.Add(Type:=msoControlButton, before:=1)
.BeginGroup = True
.Caption = "生成建表脚本"
.TooltipText = "生成建表脚本"
.Style = msoButtonCaption
.OnAction = "Create_TS_Table_Script"
End With
On Error GoTo Exception
Exit Sub
Exception:
End Sub