2
votes

When sharing a Google Sheet with a button that runs a Google Script I run into the following problem: - When anyone but myself clicks the button the script will return the following error: "You are trying to edit a protected cell or object. Please contact the spreadsheet owner to remove protection if you""

I had a couple protected ranges (deleted them now) in the sheet, but not one even close to the button. I've tried to add a button on one of the shared user's account and copied the script into a new script file (re-linking the script created/copied by the shared user to the button created by the shared user), but to no avail.

Anyone who knows the solution to this problem ?

1
Share the file... or a test - Mario Zamora

1 Answers

0
votes

Removing the protection doesn't work just by deleting the cell values. There's a sample code in Class Protection which shows adding and removing protection in sheet ranges:

 // Remove all range protections in the spreadsheet that the user has permission to edit.
 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();
   }
 }