我有一个工作表,需要为用户提供保护。
如何保护除特定范围外的整个工作表?我想保留它们以供更改。
这是我的代码,它在.Locked = false
行中返回一个运行时错误。
Sub Protect()
With main
.Protect Password:=1234
.Range("U:V").Locked = False
.Range("AH:AH").Locked = False
End With
With bakaraWS
.Protect Password:=1234
End With
If segmenWS = "" Then
Exit Sub
Else
With segmenWS
.Protect Password:=1234
.Range("E:E").Locked = False
.Range("H:H").Locked = False
End With
End If
End Sub
在保护工作表之前必须解锁单元格,或者使用UserInterfaceOnly:=True参数保护工作表,以便VBA可以操作锁定的工作表。
Sub Protect()
With main
.UnProtect Password:=1234
.Range("U:V").Locked = False
.Range("AH:AH").Locked = False
.Protect Password:=1234
End With
With bakaraWS
.Protect Password:=1234
End With
If segmenWS = "" Then
Exit Sub
Else
With segmenWS
.UnProtect Password:=1234
.Range("E:E").Locked = False
.Range("H:H").Locked = False
.Protect Password:=1234
End With
End If
End Sub
如果要使用VBA操作工作表而不首先取消对其的保护,请使用此选项。
With main
.Protect Password:=1234, UserInterfaceOnly:=True
.Range("U:V").Locked = False
.Range("AH:AH").Locked = False
End With