我有一个受保护的 Excel 工作表,没有密码。我想做的是捕获用户取消保护工作表的事件,以便我可以生成一条消息(并唠叨他们!)。我可以为应用程序设置事件检查,何时打开新工作簿等,但不能为 Unprotect 设置。
有人有想法吗?
Sjoerd
问问题
4310 次
2 回答
2
It is possible to modify the menu using Tools->Customize. Protect/Unprotect can be set to run a macro, for example:
Sub UnprotectTrap()
If ActiveSheet.ProtectContents = True Then
MsgBox "Tut,tut!"
ActiveSheet.Unprotect
Else
ActiveSheet.Protect
End If
End Sub
于 2008-10-28T22:00:18.460 回答
0
There is no way to trap the user unprotecting the sheet, but you can warn them if they save the workbook without reprotecting the sheet(s).
In the Workbook module, put this code, or something like it
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("MyProtectedSheet").ProtectContents = False Then
MsgBox "The sheet 'MyProtectedSheet' should not be left unprotected. I will protect it before saving", vbInformation
Sheets("MyProtectedSheet").Protect
End If
End Sub
于 2008-10-28T22:35:08.637 回答