What is VBA code to check if the sheet is protected in excel ?
I used this code below, the output was null
Function IsSheetProtected(sheetName As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(sheetName)
On Error GoTo 0
If Not ws Is Nothing Then
IsSheetProtected = ws.ProtectContents
Else
' If the sheet does not exist, consider it as protected
IsSheetProtected = True
End If
Use the invoke vba activity to check the excel sheet is protected or not. Use the below vb code.
Function IsSheetProtected(sheetName As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(sheetName)
On Error GoTo 0
If Not ws Is Nothing Then
IsSheetProtected = ws.ProtectContents
Else
IsSheetProtected = False
End If
End Function
Function IsSheetProtected(sheetName As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(sheetName)
On Error GoTo 0
If Not ws Is Nothing Then
IsSheetProtected = ws.ProtectContents Or ws.ProtectDrawingObjects _
Or ws.ProtectScenarios Or ws.ProtectionMode
Else
' If the sheet does not exist, consider it as protected
IsSheetProtected = True
End If