I'm running a piece of code via the Worksheet_Change Event and I have it working with a call to an unprotect sub at the beginning of the event and a matching call to a protect sub at the end of the event. This works as expected.
I'm trying to work with setting the protection to userinterfaceonly:=true in the workbook open event to negate the need to unprotect and reprotect each time the change event fires (more just to explore the functionality than anything else). Problem is that the code to change conditional formatting on a locked range inevitably errors if the worksheet is protected (even with UserInterfaceOnly = True) although it works fine and as expected if the worksheet is unprotected either manually or by VBA unprotecting the sheet before that line and re-protecting after that line.
I've played around a bit and it seems to error on anything to do with changing conditional formatting on a locked cell. I wonder if changing conditional format on a locked range while a sheet is protected isn't allowed under the scope of UserInterfaceOnly? If anyone knows if this is a limitation and if there are any other limitations to this argument, it would be great to know.
In my 'This Workbook' module I have:
Private Sub Workbook_open()
ActiveSheet.Protect userinterfaceOnly:=True
End Sub
In my worksheet's module, I have the below - the FormatConditions.Delete line errors with a runtime error 1004: Application or Object Defined Error when that Case resolves to true.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$6" Then
Application.ScreenUpdating = False
Select Case Range("D6")
Case "Select Function"
Range("F6").Value = ("")
Range("H4:I4").Select
Selection.FormatConditions.Delete <<<<<<THIS LINE ERRORS
Selection.ClearContents
Call DeleteButtons
Call HideAll
Range("D6").Select
Case "Goods In & Redelivery"
Range("F6").Value = ("EXPLANATORY TEXT")
Call DeleteButtons
Range("D10:F10").ClearContents
Call UnHideAll
Call HideCollection
Call FillDelivery
Call GIRButtons
Range("D10").Select
Case "Collection & Redelivery"
Range("F6").Value = ("EXPLANATORY TEXT")
Call DeleteButtons
Call UnHideAll
Call HideGoodsIn
Call ClearDelivery
Call CRButtons
Range("H4").Select
Case "Delivery Only"
Range("F6").Value = ("EXPLANATORY TEXT")
Call DeleteButtons
Call UnHideAll
Call HideGoodsInCollection
Call ClearDelivery
Call DelButtons
Range("H4").Select
End Select
Application.ScreenUpdating = True
End If
End Sub