2016-11-29 428 views

回答

3

我不认为有一个直接的方式来做到这一点,通过财产的方式。另外,虽然,你可以尝试用空密码来取消工作表,并捕获错误一旦失败:

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 

您可以致电此类似:

isSheetProtectedWithPassword(Worksheets("Sheet1")) 

,它将返回TrueFalse

+0

谢谢JNevill。 –