ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check if activesheet is protected (https://www.excelbanter.com/excel-programming/289718-check-if-activesheet-protected.html)

freseh

Check if activesheet is protected
 
Hello Everyone!

I have a small problem that needs a simple solution.
How do I check with VBA if my activesheet is password protected?

What I want to have is a macro that protect if it's unprotected and
vice verse.

And this doesn't work, the red text must be something else :

If ActiveSheet.Protect.Enabled = False Then
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:="bossboss"
Else
ActiveSheet.Unprotect Password:="bossboss"
End If

Thanks in advance for your help!


---
Message posted from http://www.ExcelForum.com/


chandlm[_14_]

Check if activesheet is protected
 
Freseh

change,

If ActiveSheet.Protect.Enabled = False Then

to

If ActiveSheet.ProtectContents = false Then

That should do the trick

HTH


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com