Private Sub Worksheet_Activate()
ActiveSheet.Protect "RS"
ActiveSheet.Range("B:C").Locked = False
End Sub
我正在尝试上面的代码,但没有工作,我想只解锁B和C列
答案 0 :(得分:4)
在解锁范围之前,您正在保护工作表。但由于纸张受到保护,因此无法解锁范围。交换两行代码将起作用:
Private Sub Worksheet_Activate()
ActiveSheet.Range("B:C").Locked = False ' unlock the cells, so they can be edited in a protected sheet
ActiveSheet.Protect "RS" ' protect the sheet so only unlocked cells can be edited
End Sub
答案 1 :(得分:0)
Private Sub Workbook_Activate()
Worksheets("ObjectDescriptionMapping").Range("B:C").Locked = False ' unlock the cells, so they can be edited in a protected sheet
Worksheets("ObjectDescriptionMapping").Protect "RS"
End Sub