Looping through a list of Google Calendar Users
<p>I have a list of Google Email users in a google sheet(named Master, column E). Each user also has a blank sheet named after that email address (User@Whatever.com).</p>

<p>What I'm aiming to do it go through the user list, retrieve the calendar entries for today for each user, and enter them into their relevant sheet. So far I have the following code, but it's returning </p>

<blockquote>
  <p>TypeError: Cannot call method "getEventsForDay" of null. (line 15,
  file "Calendar Update")</p>
</blockquote>

<p>Code is below:</p>

<pre><code>var employeeDataRange = SpreadsheetApp.getActiveSpreadsheet().getRange("Master!E2:E");
var employeeObjects = employeeDataRange.getValues();

for (var j=0; j&lt;employeeObjects.length; j++) {  
    var cal = CalendarApp.getCalendarById(employeeObjects[j]);
    var sheet =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName(employeeObjects[j])
    var today = new Date();

    var events = CalendarApp.getCalendarById(cal).getEventsForDay(today);
    for (var i=0;i&lt;events.length;i++) {    
        var details=[[events[i].getTitle(), events[i].getStartTime(), events[i].getEndTime(), events[i].getAllTagKeys()]];
        var row=i+1;
        var range=sheet.getRange(row,1,1,4);
        range.setValues(details);
    }
}  
}
</code></pre>

<p>Cheers,</p>

<p>Dan</p>