D. *_* O. 3 excel vba worksheet excel-vba
我们可以使用ProtectContents属性检查工作表是否受到保护.但是如何检查它是否受密码保护?
if ws.ProtectContents then
''do something
end if
Run Code Online (Sandbox Code Playgroud)
我不相信通过财产可以直接做到这一点.但是,您可以尝试使用空白密码取消保护工作表,并在失败时捕获错误:
Function isSheetProtectedWithPassword(ws As Worksheet) As Boolean
If ws.ProtectContents Then
On Error GoTo errorLabel
ws.Unprotect ""
ws.Protect
End If
errorLabel:
If Err.Number = 1004 Then isSheetProtectedWithPassword = True
End Function
Run Code Online (Sandbox Code Playgroud)
您可以这样称呼:
isSheetProtectedWithPassword(Worksheets("Sheet1"))
Run Code Online (Sandbox Code Playgroud)
它将返回True或False
| 归档时间: |
|
| 查看次数: |
6471 次 |
| 最近记录: |