Allowing code to change protected sheets

As a long time user of Excel I know how to do what I need it to do but looking to move a lot of my work to LO calc. One thing I need to be able to do is to protect sheets but still allow code to change protected cells. I can do that in Excel by setting the protection to only stopping human interaction (but I need to do that every time I open the spreadsheet). Does Calc have something similar and if so is it persistent? What I don’t really wan to be doing is unlocking, changing, relocking.

TIA

You don’t need to do anything. In LibreOffice Calc cell protection does not prohibit changes by code.
You can, however, abolish an existing protection by theSheet.Unprotect(Password) and apply protection by theSheet.Protect(Password)

Thanks for popping up. For some odd reason a snippet of code throws an exception but only when the sheet is protected, but a test of a simple “put this value here” works fine. Thanks.

What statement/command makes what exception occur?