Private Sub Worksheet_Activate()
Dim cbs As CommandBarControl
Dim cmb As CommandBar
Set cmb = Application.CommandBar("&Edit")
Set cbs = cmb.FindControl(ID:=848)
MsgBox cbs.Caption
End Sub
Private Sub Workbook_SheetBeforeDelete(ByVal Sh As Object)
[COLOR=#008000]'name of main sheet = "ShButtons"[/COLOR]
Dim SheetFullName As String
Dim SheetParsedName As String
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
[COLOR=#008000]'get the full name of the sheet being deleted[/COLOR]
SheetFullName = ActiveSheet.Name
[COLOR=#008000]'get the first 9 letters of the name of sheet being deleted[/COLOR]
[COLOR=#008000]'ShButtons has 9 letters; this is ensure code works for copies of copies as well[/COLOR]
SheetParsedName = Left(SheetFullName, 9)
[COLOR=#008000]'match first 9 letters and secret code[/COLOR]
[COLOR=#008000]'copy sheet only is both matches[/COLOR]
[COLOR=#008000]'let user delete all else[/COLOR]
If SheetParsedName = "ShButtons" And ActiveSheet.Range("L2").Value = "mysecretstring@99" Then
ActiveSheet.Copy After:=Sheets(ActiveWorkbook.Worksheets.Count)
End If
End Sub
Private Sub UserForm_Activate()
Call PreventNameChange
End Sub
Sub PreventNameChange()
Dim i As Integer
For i = 1 To ThisWorkbook.Worksheets.Count
Worksheets(i).Activate
If Range("L2").Value = "mysecretstring@99" Then
If ActiveSheet.Name <> "ShButtons" Then
ActiveSheet.Unprotect "password"
ActiveSheet.Name = "ShButtons"
ActiveSheet.Protect "password"
Exit Sub
End If
End If
Next i
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim i As Integer
For i = 1 To ThisWorkbook.Worksheets.Count
' Worksheets(i).Activate
If Worksheets(i).Range("L2").Value = "[COLOR=#574123]mysecretstring@99[/COLOR]" Then
If Worksheets(i).Name <> "[COLOR=#574123]ShButtons[/COLOR]" Then
Worksheets(i).Name = "[COLOR=#574123]ShButtons[/COLOR]"
Exit Sub
End If
End If
Next i
End Sub