MsgBox to tell if worksheet is protected or not protected

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
Here's what I have, am trying to run code depending on whether or not the worksheet is protected.

Sheets("SheetName").Select

If ActiveSheet.Unprotect = True Then
MsgBox ("Not Protected")
'Run Code 1 Here
Exit Sub
End If

If ActiveSheet.Protect = True Then
MsgBox ("Protected")
'Run Code 2 here
Exit Sub
End If

but this only seems to protect the sheet if it isn't protected and vice versa...
:(
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,

Your code is running the Protect method. You are not checking to see whether or not the sheet is protected. To do that, try something like this:-

Code:
    Sheets("SheetName").Select

    If Sheet1.ProtectContents = False Then
        MsgBox ("Not Protected")
        'Run Code 1 Here
        Exit Sub
    End If

    If ActiveSheet.ProtectContents = True Then
        MsgBox ("Protected")
        'Run Code 2 here
        Exit Sub
    End If
 
Upvote 0
Thanks!!

Ended up with this!

If Sheets("Permitted Constituents").ProtectContents = True Then
MsgBox "Sheet is protected"
'Code 1 here
Else
MsgBox "Sheet is unprotected"
'Code 2 here
End If
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top