I've written a function in Spreadsheet's Script Editor that is meant to focus on cell containing current date. Generally it works when function is fired by menu entry, but after loading spreadsheet it won't focus on any cell.
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Go to Today",
functionName : "goToToday" // goToToday() contains same code as last 3 lines of onOpen()
}];
spreadsheet.addMenu("Script", entries); // works on manual run and on startup
var s = spreadsheet.getSheetByName("Sheet1");
var r = 25 + s.getRange("I4").getValue();
s.setActiveSelection(s.getRange("A" + r )); // works on manual run, doesn't work on startup
};
Following Bryan's answer, I tried another possible code that would close the dialog automatically.
A few minor changes in the way I call the UiApp popup.
function onOpen() {
var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var ui = SpreadsheetApp.getUi();
ui.createMenu('Goto today').addItem('go !','goToToday').addToUi();
var app = UiApp.createApplication().setHeight(40).setWidth(180).setTitle('Start');
var btn = app.createButton('Go to Today in cell A'+(25 + (s.getRange("I4").getValue())), app.createServerHandler("goToToday"))
.setStyleAttributes({'fontFamily':'arial','fontSize':'10pt','fontWeight':'bold','color':'white','background':'#3870ff'}).setPixelSize(175,35);
app.add(btn);
SpreadsheetApp.getActive().show(app);
}
function goToToday() {
var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var r = 25 + s.getRange("I4").getValue();
s.setActiveSelection(s.getRange("A" + r ));
return UiApp.getActiveApplication().close();
}