Time driven function in Google script <p>I am trying to download the data from a website every hour using Google script. The code is shown as below. When I manually run the function CSV_sgj, I can receive the desired information in email. But when I set the function as time driven (every hour), what I get are all #VALUE!. </p> <p>I found a similar question and tried to change </p> <pre><code>var sheet = SpreadsheetApp.getActiveSheet(); </code></pre> <p>to</p> <pre><code>var sheet = SpreadsheetApp.openById("0AtAYfCLk3-h7dDBnckdSZkNXbkZBLXBHV200SGtuZnc"); </code></pre> <p>but it still does not work.</p> <p>Many thanks in advance for help!</p> <p>The full code is below.</p> <pre><code>function readRows() { var sheet = SpreadsheetApp.getActiveSheet(); var rows = sheet.getDataRange(); var numRows = rows.getNumRows(); var values = rows.getValues(); for (var i = 0; i &lt;= numRows - 1; i++) { var row = values[i]; Logger.log(row); } }; /** * Adds a custom menu to the active spreadsheet, containing a single menu item * for invoking the readRows() function specified above. * The onOpen() function, when defined, is automatically invoked whenever the * spreadsheet is opened. * For more information on using the Spreadsheet API, see * https://developers.google.com/apps-script/service_spreadsheet */ function CSV_sgj() { readRows(); var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:N32"); var data = range.getValues(); var csv = ""; for (var i = 0; i &lt; data.length; ++i) { csv += data[i].join(",") + "\r\n"; } var csvFiles = [{fileName:"PSI5.csv", content:csv}] MailApp.sendEmail("xxxxxx@gmail.com", "CSV", "", {attachments: csvFiles}); } </code></pre>