Reputation: 17
I would like a spreadsheet to automatically include the name of its parent folder in cell A1 of the active sheet onOpen. I have a script that successfully achieves this if I run it manually, yet I am not able to accomplish this onOpen. As recommended below, I have tried using an installable onOpen trigger but that is not a solution as I want to make copies of the spreadsheet and have the folder name included onOpen. The trigger will not copy with the spreadsheet so I am back to square one. The issue is with permissions, I believe? Any workaround?
Upvotes: 0
Views: 130
Reputation: 38131
As recommended below, I have tried using an installable onOpen trigger but that is not a solution as I want to make copies of the spreadsheet and have the folder name included onOpen. The trigger will not copy with the spreadsheet so I am back to square one. The issue is with permissions, I believe? Any workaround?
No, the issue isn't with permissions, the issue is related to other concepts. I'll try to make a summary including the minimal of them that I think are required for this question to help you learn the basic terms so you could scan this site and others to find the stuff you will need or that will help you to make more specific questions:
Upvotes: 0
Reputation: 64032
You can use something like this to create an installable onOpen trigger if one is not already in the project.
function createOpenTrigger(funcname) {
if(funcname) {
if(!isTrigger(funcname)) {
ScriptApp.newTrigger(functionName).forSpreadsheet(SpreadsheetApp.getActive()).onOpen().create();
}
}
}
function isTrigger(funcName){
var r=false;
if(funcName){
var allTriggers=ScriptApp.getProjectTriggers();
for(var i=0;i<allTriggers.length;i++){
if(funcName==allTriggers[i].getHandlerFunction()){
r=true;
break;
}
}
}
return r;
}
Of course, the user will have to approve it first.
Upvotes: 1