參考對岸的網站寫入了下列的程式
Private Sub Workbook_BeforeClose(Cancel As Boolean)
showhide (bHide = True)
End Sub
Private Sub Workbook_Open()
showhide (bHide = False)
End Sub
Sub showhide(Optional bHide As Boolean)
Dim cmb As CommandBar
Static col As New Collection
If bHide Then
For Each cmb In Application.CommandBars
If cmb.Type = msoBarTypeMenuBar Or cmb.Type = msoBarTypeNormal Then
If cmb.Visible Then
cmb.Enabled = False
If cmb.Visible Then cmb.Visible = False
col.Add cmb, cmb.Name
End If
End If
Next cmb
Else
If col Is Nothing Or col.Count = 0 Then
For Each cmb In Application.CommandBars
If cmb.Type = msoBarTypeMenuBar Or cmb.Type = msoBarTypeNormal Then
If Not cmb.Visible Or Not cmb.Enabled Then
cmb.Enabled = True
If (Not cmb.Visible) And cmb.Enabled Then cmb.Visible = True
End If
End If
Next cmb
Else
For Each cmb In col
If Not cmb.Visible Or Not cmb.Enabled Then
cmb.Enabled = True
If (Not cmb.Visible) And cmb.Enabled Then cmb.Visible = True
End If
Next cmb
End If
Set col = Nothing
End If
End Sub