Option Explicit
Sub EditMenu()
On Error GoTo Err_Hnd
Dim c As Office.CommandBarButton
Dim cb As Office.CommandBar
Set cb = Excel.CommandBars("Ply")
For Each c In cb.Controls
If c.ID = 945 Then
c.Visible = False
Exit For
End If
Next c
Set c = cb.Controls.Add(Type:=msoControlButton, Before:=1)
c.Caption = "&Insert Sheet..."
c.OnAction = "InsertSheet"
c.Visible = True
Exit Sub
Err_Hnd:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
On Error Resume Next
Set cb = Excel.CommandBars("Ply")
cb.Reset
End Sub
Sub InsertSheet()
'This needs to go in a module.
On Error GoTo Err_Hnd
If ThisWorkbook.Name = ActiveWorkbook.Name Then
Const strPW As String = "MyPassword"
ThisWorkbook.Unprotect Password:=strPW
ThisWorkbook.Sheets.Add
ThisWorkbook.Protect Password:=strPW, Structure:=True, Windows:=False
Else
If Not ThisWorkbook.ProtectStructure Then
ThisWorkbook.Sheets.Add
Else
MsgBox "Workbook protected for structure!", vbExclamation, "Cannot Add Sheet"
End If
Exit Sub
Err_Hnd:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub
Sub ResetMenu()
On Error Resume Next
Dim cb As Office.CommandBar
Set cb = Excel.CommandBars("Ply")
cb.Reset
End Sub