A spreadsheet with multiple tabs have 10 editors/access. I wanted to lock some ranges in each tab from 8 of those editors.
When I ran google app script written below, it also lock the 8 editors from editing the tab name and even the tab color. Can advise on where i went wrong? I want them to still able to change the tab name and colour of the tab.
function addClassProtectionFor_Current(){ //Main function to run
var currentclasstab = SpreadsheetApp.getActiveSheet();
// Remove all range protections in the spreadsheet
var protections = currentclasstab.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
protection.remove();
}
var protection = currentclasstab.protect();
//restrict editors to owner
protection.getRange().getA1Notation();
var eds = protection.getEditors();
protection.removeEditors(eds);
//Add Editors to give access to the protected ranges
protection.addEditors(["me.gmail.com","you@gmail.com"]);
//set unprotected ranges
var ranges = protection.getUnprotectedRanges();
//Ranges to leave unlocked
var data = ["A5:V19","B23:V26","B29:V35","B39:V45"];
data.forEach(res => { //LOOPS INTO EVERY ARRAY CONTAINING SPECIFIC RANGES
ranges.push(currentclasstab.getRange(res));
protection.setUnprotectedRanges(ranges); //REMOVES THE PROTECTION ON THE RANGE
});
}