Hi Hugues,
it sound like you want to programmatically insert a button into a sheet, and configure the button to execute a function.
Here is how to do this:
1. Programmatically insert an image onto the sheet (shaped like a button), then
2. Programmatically assign a script to the image
Here is the code:
- Add the image of the button to your home folder, and name it "mybutton.png"
- Then run the addButton() function
- Viola!
function addButton() {
var blob = DriveApp.getRootFolder().getFilesByName("mybutton.png").next().getBlob()
var sht = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var img = sht.insertImage(blob,1,1)
img.assignScript("helloWorld")
}
function helloWorld() {
SpreadsheetApp.getUi().alert("Hello world")
}