ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test if protected (https://www.excelbanter.com/excel-programming/357065-test-if-protected.html)

steven

Test if protected
 
How do you tell if the active file workbook protect is activated? For Sheet
protect test I have used:

If ActiveSheet.ProtectContents = True Then ............

For the Workbook I tried:

If ActiveWorkbook.ProtectContents = True Then ..........

But that does not work.

Thanks for your help,

Steven

[email protected]

Test if protected
 
Just run

ActiveWorkbook.Protect Contents:= true
or
ActiveWorkbook.Protect Contents:= true password:= "passkey"

then you know it is.

and

ActiveWorkbook.Unprotect
or
ActiveWorkbook.Unprotect Password:= "passkey"

when you need to unprotect it.

Do you really need to query the status?
You could try to change the value of a cell you know should be locked
and intercept the error if Protection is enabled.


[email protected]

Test if protected
 
This works too and can be modified to check different criteria;

Sub CheckProtection()

ActiveSheet.Protect

' Check the ability to insert columns on a protected sheet.
' Notify the user of this status.
If ActiveSheet.Protection.AllowInsertingColumns = True Then
MsgBox "The insertion of columns is allowed on this protected
worksheet."
Else
MsgBox "The insertion of columns is not allowed on this
protected worksheet."
End If

End Sub


Chip Pearson

Test if protected
 
Steven,

If ActiveWorkbook.ProtectStructure Or
ActiveWorkbook.ProtectWindows Then
Debug.Print "workbook is protected"
Else
Debug.Print "workbook not protected"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Steven" wrote in message
...
How do you tell if the active file workbook protect is
activated? For Sheet
protect test I have used:

If ActiveSheet.ProtectContents = True Then ............

For the Workbook I tried:

If ActiveWorkbook.ProtectContents = True Then ..........

But that does not work.

Thanks for your help,

Steven





All times are GMT +1. The time now is 01:20 AM.

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