简体   繁体   中英

Excel - VBA Check if worksheet is unprotected

With if Worksheets("test").ProtectContents I can recognize if the worksheet is protected. It only returns a true, right?

How can I check if it is unprotected?

If Worksheets("test").ProtectContents = True Then: Exit Sub:

For Each cell In Range("B6:B112")
...
Next cell

Else:

If Not Worksheets("test").ProtectContents Then
Dim rng As Range
...

The foreach loop have to execute when the sheet is protected. And the part at if not worksheet.. is for the part when the sheet is unproteced. thx.

I guess this is what you are looking for,

If ActiveSheet.ProtectContents = True Then
MsgBox "Protected"
Else
MsgBox "Not protected"
End If

if not, please comment. hopefully we shall able to resolve your issue.

尝试这样:

If Not Worksheets("test").ProtectContents Then Exit Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM