|
楼主 |
发表于 2012-5-30 11:23
|
显示全部楼层
弄了一个晚上,东拼西凑,终于搞掂:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$30" Then
If Range("A30").Value = "lock" Then
Me.Unprotect Password:="123"
Cells.Locked = False
'Range("A5:D28").Locked = True
Range("A30").ClearComments
Range("A30").AddComment.Text Text:="lock"
Range("A5:D28").SpecialCells(2, 23).Locked = True
Me.Protect Password:="123"
Else
Me.Unprotect Password:="123"
Range("A30").ClearComments
Range("A30").AddComment.Text Text:="unlock"
End If
ElseIf Target.Column >= 1 And Target.Column <= 4 And Target.Row >= 5 And Target.Row <= 28 Then
If Range("A30").Value = "lock" Then
Me.Unprotect Password:="123"
Cells.Locked = False
Range("A5:D28").SpecialCells(2, 23).Locked = True
Range("A5:D28").SpecialCells(xlCellTypeFormulas, 23).Locked = True
Me.Protect Password:="123"
Else
Me.Unprotect Password:="123"
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ss
If Target.Address = "$A$30" Then
ss = InputBox(" 请输入操作口令:", "温馨提示:")
If ss <> "123" Then Range("A29").Select
End If
End Sub
|
|