我试图保护我的 excel 中的一些列。我尝试了下面提到的这段代码,但它不起作用任何人都可以帮助我解决这个问题。
Sub ARCProtectPwdRFQ()
ActiveSheet.Unprotect Password:="arc"
Cells.Locked = False
ActiveSheet.Range("A1", "D100").Locked = True
Columns("I:I").EntireColumn.Locked = True
ActiveSheet.Protect Password:="arc", UserInterFaceOnly:=True 'DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
最佳答案
这是你正在尝试的吗?
Sub ARCProtectPwdRFQ()
Dim ws As Worksheet
'~~> Change this to the relevant sheet
Set ws = Sheet1
With ws
.Unprotect Password:="arc"
.Cells.Locked = False
.Range("A1", "D100").Locked = True
.Columns("I:I").EntireColumn.Locked = True
.Protect Password:="arc", UserInterFaceOnly:=True, _
DrawingObjects:=True, Contents:=True, Scenarios:=True
.EnableSelection = xlUnlockedCells
End With
End Sub
要防止复制,只需使用 .EnableSelection = xlUnlockedCells
禁用锁定单元格的选择即可。 .还要避免使用
Activesheet
除非并且直到绝对必要。使用对象。
关于excel - 如何防止从 protected excel表中复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69304937/