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 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
}
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