Google Apps Script for Sheets

52 views
Skip to first unread message

Matt Reynolds

unread,
Mar 27, 2023, 12:34:59 AM3/27/23
to Google Apps Script Community
Good evening, everyone!

I am attempting to copy sheets w/their permissions while trying to name them as they are created. I keep having issues and I am hopeful that someone will be able to assist me, if this is even doable. I have copied my code below.

I just started learning JS about three weeks, so any assistance would be greatly appreciated! Thank you.

function copyWithProtections(){
  const sh = SpreadsheetApp.getActiveSpreadsheet();
  const ss = sh.getSheetByName("#2");
  const prot = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET)
  const sheetListArray = ["#3","#4","#5","#6","#7","#8","#9","#10","#11","#12","#13","#14","#15","#16","#17","#18","#19","#20","#21","#22","#23","#24","#25","#26","#27","#28","#29","#30","#31"]

  for (let nSheet = 2nSheet <= sheetListArray.lengthnSheet++);
  let p;

  for (let i in prot) {
    p = nSheet.getRange(prot[i].getRange().getA1Notation()).protect();
    p.removeEditors(p.getEditors());
    if (p.canDomainEdit()) {
      p.setDomainEdit(false);
    }
  }
}

function renameSheets() {
  let nSheet = ss.copyTo(sh).setName(sheetListArray[nSheet]);
}
Reply all
Reply to author
Forward
0 new messages