Reputation: 1
Thank you for your great posts!
I am looking for a code that will cause jumping automatically to the current date after opening a table in Google Sheets (via a share link). Your code (see below) works great if I am signed in. When I create a share link (with or without edit rights), the code does not work. I tried the link with different browsers (Chrome, Edge, Firefox) ... What could be the problem?
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var data = sh.getDataRange().getValues();
var today = new Date().setHours(0,0,0,0);
for(var n=0;n<data[0].length;n++){
var date = new Date(data[0][n]).setHours(0,0,0,0);
if(date==today){break};
}
n++;
sh.getRange(1,n).activate();
}
Kind regards
Here the link to your code: How to set background color for a row based on current date in Google Docs Spreadsheet?
Upvotes: 0
Views: 90
Reputation: 18985
The onOpen(e)
function is a simple trigger that runs only if the user at the keyboard is signed in to their Google account and has edit access to the spreadsheet.
The simple triggers onOpen(e)
, onEdit(e)
and onSelectionChange(e)
will not run when a file is opened in read-only mode. The same is true with other kinds of scripts as well. In other words, if you share the file as "can view" or "can comment", no scripts or add-ons will be available.
To make it work, you will have to share the spreadsheet file as "can edit". Note that you you can still protect the spreadsheet through Data > Protected sheets and ranges.
See the jumpToToday_ script for an alternative that supports multiple sheets in the same spreadsheet file.
Upvotes: 1
Reputation: 1
unfortunately, this won't work for you. by default, all non-signed users (and signed-in users which did not authorize scripts) are protected from "harmful" scripts which may be included with the spreadsheet. all scripts are treated as "harmful" by default including your onOpen script.
Upvotes: 0