01-08-2011, 10:08 AM
The Function code for checking if a worksheet or workbook is protected is (scroll inside window) :
The usage is (scroll inside window) :
For more explanations go to:
PHP Code:
Function IsProtected(objXL As Object) As Boolean
Dim wksht As Excel.Worksheet
Dim cell As Excel.Range
Select Case TypeName(objXL)
Case "Worksheet"
If objXL.ProtectContents Then
' still doesn't mean you can't edit the worksheet!
Select Case Cells.Locked
Case True ' all cells are locked AND worksheet is protected
IsProtected = True
Exit Function
End Select
End If
Case "Workbook"
If objXL.ProtectStructure Then
IsProtected = True
Exit Function
End If
For Each wksht In objXL.Worksheets
If wksht.ProtectContents Then
' still doesn't mean you can't edit the worksheet!
Select Case Cells.Locked
Case True ' all cells are locked AND worksheet is protected
IsProtected = True
Exit Function
End Select
End If
Next wksht
Case "Range"
If objXL.Cells.Count = 1 Then
If (objXL.Locked And objXL.Parent.ProtectContents) Or (IsProtected(objXL.Parent.Parent)) Then
IsProtected = True
Exit Function
End If
Else
For Each cell In objXL
If (cell.Locked And cell.Parent.ProtectContents) Or (IsProtected(cell.Parent.Parent)) Then
IsProtected = True
Exit Function
End If
Next cell
End If
End Select
End Function
The usage is (scroll inside window) :
PHP Code:
Dim wkb As Excel.Workbook
Set wkb = ActiveWorkbook
If IsProtected(wkb) Then
Msgbox "It's protected!"
End If
' or
Dim wksht As Excel.Worksheet
Set wksht = ActiveSheet
If IsProtected(wksht) Then
Msgbox "It's protected!"
End If
' or
Dim rng as Excel.Range
Set rng = Range("A3")
If IsProtected(rng) Then
Msgbox "It's protected!"
End If
For more explanations go to:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************