在不保护工作簿的情况下,禁止删除工作表以及更给工作表名称。
Option Explicit
Public strBeforeSheetName As String
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
strBeforeSheetName = Sh.Name
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
'-------------------
'変回更改前名称
'-------------------
If strBeforeSheetName <> vbNullString And strBeforeSheetName <> Sh.Name Then
Sh.Name = strBeforeSheetName
End If
'-------------------
'禁止削除工作表
'-------------------
'保护工作簿,没有密码
ThisWorkbook.Protect , True
'保护工作簿,没有密码
Application.OnTime Now, "ThisWorkbook.RemoveProtection"
End Sub
Sub RemoveProtection()
'撤销保护工作簿
ThisWorkbook.Unprotect
End Sub