I created a button in my spreadsheet with an script function that will insert rows above a target row and then protect the rows below the inserted rows.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var as = ss.getActiveSheet();
var startRow = 8
var startCol = 1
var numRows= as.getMaxRows() - startRow + 1;
var numCols = as.getMaxColumns();
as.getRange(startRow,startCol,numRows,numCols)
.protect()
.removeEditors(as.getRange(startRow,startCol,numRows,numCols).protect().getEditors())
Above is my code. The problem with this code is that it’s being called by the active user. So he is still included as an editor of the protected range. But what I wanted is to remove the active user.
I can run this function as the effective user, and it will work the way I wanted it. However, it means that I have to run this function manually or time-based.
I want this function to run by me, not by the active user (editor), ONLY when the button is clicked. So the active user will be removed as an editor. How do I do this? Any help is appreciated.
I searched all over the internet to find similar situation but I haven’t found any. Or maybe didn’t recognize it as similar to my case. I’m a newbie.
Dorcas Domingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.