I wrote an Apps Script file to protect cells on-edit, and it was working for a while, but it stopped working recently. I suspect I hit some sort of cap on the number of protected ranges one sheet can have. I’d rather not delete thousands of protected ranges manually, so I’m trying to write a script that will remove all protections automatically when run.
I visited the Class Protection page of the Apps Script documentation site. It recommended a script to do exactly what I need, but that script times out and throws an error when run. The code is below:
function removeProtections() {
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
if (protection.canEdit()) {
protection.remove();
}
}
}
In the execution log, I see two messages: First, a notice message saying “Execution started.” Second, after the execution runs for a while, I get an error message saying “Exceeded maximum execution time.”
David Christensen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.