How to Remove Editors from Protected Cells or Permanently Protect Cells in Google Sheets -
i'm trying permanently lock/protect cells on 14 different sheets (1 hidden workers formula stuff). have them locked , no 1 can edit if add them editor. template, make copies of each client (and new clients) staff. staff works on sheet , employees allowed edit cells work do.
the problem if have workbook1
x cells locked on different sheets, make copy, rename workbook - client#id
, add them employees john , jane, working on client, editors; can edit every cell, including protected ones (they added editors protected cells too). doesn't on original, happens copy made of template. have go through 13 sheets , remove them protected cells.
i'm trying remove them automatically script add-on want turn button or later...
or there better way fix bug?
google has example of removing users , keeping sheet protected , have tried add in need make work, doesn't when run test add-on spreadsheet. open new app script project spreadsheet , enter in example code google
// protect active sheet, remove other users list of editors. var sheet = spreadsheetapp.setactivesheet(january); var protection = sheet.protect().setdescription('activity log'); var unprotected = sheet.getrange('a2:n7'); protection.setunprotectedranges([unprotected]); // ensure current user editor before removing others. otherwise, if user's edit // permission comes group, script throw exception upon removing group. var me = session.geteffectiveuser(); protection.addeditor(me); protection.removeeditors(protection.geteditors()); if (protection.candomainedit()) { protection.setdomainedit(false); }
for can write script function set protection ranges , add editors sheets well.
please check sample apps script code add protection range in sheet below:
function addprotection() { // protect range a1:b10, remove other users list of editors. var ss = spreadsheetapp.getactive(); var range = ss.getrange('a1:b10'); var protection = range.protect().setdescription('sample protected range'); // var me = session.geteffectiveuser(); // array of emails add them editors of range protection.addeditors(['email1','email2']); // array of emails remove users list of editors protection.removeeditors(['email3','email4']); }
hope helps!
Comments
Post a Comment