ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   test sheet for protection (https://www.excelbanter.com/excel-programming/385774-test-sheet-protection.html)

David

test sheet for protection
 
Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
....but alas, no joy, please help

Mike

test sheet for protection
 
You were nearly there, try this:-

Sub isitprotected()
If ActiveSheet.ProtectContents = True Then
MsgBox ("Protected")
Else
MsgBox ("Unprotected")
End If
End Sub

Mike

"David" wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help


Vergel Adriano

test sheet for protection
 
David,

Check the ProtectContents property:

If ActiveSheet.ProtectContents Then
MsgBox "sheet is protected"
Else
MsgBox "Sheet is not protected"
End If



--
Hope that helps.

Vergel Adriano


"David" wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help


David

test sheet for protection
 
excellent! Thank you

"Mike" wrote:

You were nearly there, try this:-

Sub isitprotected()
If ActiveSheet.ProtectContents = True Then
MsgBox ("Protected")
Else
MsgBox ("Unprotected")
End If
End Sub

Mike

"David" wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help


David

test sheet for protection
 
Excellent! Thank you

"Vergel Adriano" wrote:

David,

Check the ProtectContents property:

If ActiveSheet.ProtectContents Then
MsgBox "sheet is protected"
Else
MsgBox "Sheet is not protected"
End If



--
Hope that helps.

Vergel Adriano


"David" wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help


Dave Peterson

test sheet for protection
 
There are different levels of protection...

Option Explicit
sub testme()
msgbox wksisprotected(activesheet)
end sub
Function WksIsProtected(wks As Worksheet) As Boolean
If wks.ProtectContents = True _
Or wks.ProtectDrawingObjects = True _
Or wks.ProtectScenarios = True Then
WksIsProtected = True
Else
WksIsProtected = False
End If
End Function



David wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help


--

Dave Peterson

Paul D.[_2_]

test sheet for protection
 
I put this code in the Workbook BeforeClose Event to make sure the Sheet is
protected before I close the App. Works perfectly when I try to close the app
using the Close Button at top right of the window. When I close the App using
the code Application.Quit in a close button I put into a form,
ActiveSheet.ProtectContents is always False. If I use
Sheets("name").ProtectContents, same thing always False.

Does that make sense, is there a work around?

"Mike" wrote:

You were nearly there, try this:-

Sub isitprotected()
If ActiveSheet.ProtectContents = True Then
MsgBox ("Protected")
Else
MsgBox ("Unprotected")
End If
End Sub

Mike

"David" wrote:

Been racking my brains again...
Tried:
On Error Resume Next
If Not ActiveSheet.Protection Is Nothing Then
MsgBox "sheet is protected"
Else: MsgBox "Sheet is not protected"
On Error GoTo 0
End If
...but alas, no joy, please help



All times are GMT +1. The time now is 11:34 PM.

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