Is It Possible to Create Buttons with Google Apps Script?

Is It Possible to Create Buttons with Google Apps Script?

I would like to have a list with Names and next to them a Button, that brings me to that Spreadsheet. But i dont want to create a Button for each one manually.

Otherwise i would create a Sidebar with a Dropdown.. but would prefer the first solution :)

Thank you

Now I just have a single Name with a Single Button

2

2 Answers

Yes, you can insert images with Apps Script and use it as buttons. Use sheet.insertImage() to insert the image and assignScript(functionName) to assign the function.

See example below:

//Function to insert image
function insertImg() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var image = sheet.insertImage("", 1, 1); //change the URL to the image you prefer

image.assignScript("sheet"); //assign the function to the image

}

//function that takes you to the sheet you specify
function sheet() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet2'), true); //change Sheet2 to the name of the sheet where you want to go
}
4

Description

You could simply have a checkbox in the column next to the sheet names. When the user clicks a checkbox the selected sheet will become active.

Then using a simple onEdit(e) trigger keep an eye on the checkbox column.

Simple, low overhead, no image file needed.

Code.gs

function onEdit(e) {
  try {
    if( ( e.value === undefined ) || ( e.value === "" ) ) return;
    if( e.range.getSheet().getName() === "SheetList" ) {
      if( e.range.getColumn() === 2 ) {
        e.range.setValue(false);
        e.source.setActiveSheet(e.source.getSheetByName(e.range.offset(0,-1).getValue()));
      }
    }
  }
  catch(err) {
    SpreadsheetApp.getUi().alert(err);
  }
}

Reference

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.