简体   繁体   English

解锁Excel VBA中受保护工作表中的列

[英]unlock column in protected sheet in excel vba

Private Sub Worksheet_Activate()
ActiveSheet.Protect "RS"
ActiveSheet.Range("B:C").Locked = False
End Sub

I am trying above code but not working, i want to unlock only B and C column 我正在尝试上面的代码,但无法正常工作,我只想解锁B和C列

You are protecting the sheet before you unlock the range. 在解锁范围之前,您正在保护工作表。 But since the sheet is protected, the range cannot be unlocked. 但是,由于工作表受到保护,因此无法解锁范围。 Swap the two lines and the code will work: 交换两行,代码将起作用:

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
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM