level 1
在ThisWorkbook 中放入如下代码
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Select ' Sheet1 是指你要保护的表名。
ActiveSheet.Unprotect Password:="123"
Columns("B:B").Locked = True
Columns("C:C").Locked = True
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
在Sheet1 的代码中放入如下代码
Public B_Value As Boolean, C_Value As Boolean
Private Sub Worksheet_Activate()
B_Value = False
C_Value = False
ActiveSheet.Unprotect Password:="123"
Columns("B:B").Locked = True
Columns("C:C").Locked = True
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Temp_key As String
If Target.Column = 2 Then
If B_Value Then
Exit Sub
Else
Temp_key = InputBox("Pls key in the Key!")
If Temp_key = "bbb" Then
B_Value = True
ActiveSheet.Unprotect Password:="123"
Columns("B:B").Locked = False
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End If
End If
If Target.Column = 3 Then
If C_Value Then
Exit Sub
Else
Temp_key = InputBox("Pls key in the Key!")
If Temp_key = "ccc" Then
C_Value = True
ActiveSheet.Unprotect Password:="123"
Columns("C:C").Locked = False
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End If
End If
End Sub
2010年04月24日 09点04分