I have protected a sheet using:
Sub ProtectSheet()
Sheet1.Protect AllowFormattingCells:=True, AllowSorting:=True, AllowFiltering:=True, UserInterfaceOnly:=True
Sheet1.EnableOutlining = True
End Sub
When I click a button that runs the following macro, it works:
Sub UnprotectSheet()
Sheet1.Unprotect
End Sub
When I make a worksheet change which triggers the following sequence:
Private Sub Worksheet_Change(ByVal target As Excel.Range)
'Application.EnableEvents = False
Call PerfromAction(target)
'Application.EnableEvents = True
End Sub
Sub PerfromAction(t As Range)
If dbg = False Then On Error GoTo ErrHandler
'Protection start
Dim bProtected As Boolean
bProtected = CheckProtection
Call UnprotectSheet
... more
End sub
Sub UnprotectSheet()
Sheet1.Unprotect
End Sub
Then I get the attached error message on the line Sheet1.Unprotect. I tried adding Application.DisplayAlerts = False before unprotecting. But then the macro stopped already on Application.DisplayAlerts = False and the popup appeared. If I tell the macro to continue, it continues and finishes successfully despite the popup.
Why does this popup appear?
Run time error.png
PS. I can't upload the workbook as is because it contains lot's of company data. If I remove everything from the workbook, I don't get an error message any more when running the exact same macro. I don't know why.
Bookmarks