vba 在excel vba中解锁受保护工作表中的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21037946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:19:52  来源:igfitidea点击:

unlock column in protected sheet in excel vba

excelvba

提问by Shriram Sapate

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 列

回答by teylyn

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

回答by Shriram Sapate

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