工作表的代码模块将这个,这将放置一个提醒在状态栏(这可以避免需要锁定/解锁工作表,以便将状态写入单元格A1)。
把它放在Sheet1代码模块中。每次激活sheet1时宏都会执行。
Private Sub Worksheet_Activate()
If ActiveSheet.ProtectContents then
Application.StatusBar = "This sheet is protected"
Else:
Application.StatusBar = "This sheet is unprotected"
End If
End Sub
Private Sub Worksheet_Deactivate()
Application.StatusBar = False
End Sub
保护/解除保护,你可以添加这一个插入>模块工作表。然后附加这些宏以分离命令按钮,或者从Developer> Macros功能区运行。
Const myPassword as String = "password" '<-- replace "password" with your password
Sub Sht1Protect()
Sheet1.Protect myPassword
End Sub
Sub Sht1Unprotect()
Sheet1.Unprotect myPassword
End Sub
为了保证片始终受到保护,当你关闭文件,工作簿的代码模块
Private Sub Workbook_Close()
Sht1Protect
End Sub
您可能需要额外的处理,以控制该文件是否被保存/未插入此保存等
谢谢,brettdj - 这可以满足我的要求。使用activex控件对使用它们的VBA代码有任何影响吗? – JohnM 2013-03-20 22:24:58