Skip to content

Instantly share code, notes, and snippets.

@xhiroga
Created October 26, 2020 02:54
Show Gist options
  • Save xhiroga/0e24b0e957afd70fdd59482fa62f0bbc to your computer and use it in GitHub Desktop.
Save xhiroga/0e24b0e957afd70fdd59482fa62f0bbc to your computer and use it in GitHub Desktop.
[GAS] protect all sheets
function protectAllSheets() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shs = ss.getSheets();
var me = Session.getEffectiveUser();
for (var i = 0; i < shs.length; i++){
var sheet = shs[i]
var protection = sheet.protect().setDescription('protect sheet by "function protectAllSheets()"');
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment