Home > OS >  Is there a way to get the "parent" Spreadsheet which triggered the code?
Is there a way to get the "parent" Spreadsheet which triggered the code?

Time:03-17

I have a script that executes a code, i've attached it to some buttons in differents sheets and inside this code i need to get the sheet name that contains the buttom that triggered the script. Is there a way to get it?

I've coded this so far:


  let sht = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Escopo - Financeiro");

  var nomeDoc = sht.getRange("A2").getValue();
  var modulo = sht.getRange("B1").getValue();

So i need to change the .getSheetByName("Escopo - Financeiro") code to fit my needs.

I was wondering if i could use some certain of "this" or "parent" statement, but i havent found it.

CodePudding user response:

So since i've bounded my script to a button which is into an active spreadsheet, replacing the SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Escopo - Financeiro"); part of the code to SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); solved the problem.

  • Related