title: Why am I getting "TypeError: Cannot read property 'getRange' of undefined" for line 2 sheet.getRange?
body: <p>This function was working perfectly until this morning and I can't find the reason for the error... I have edited the first line to include the Spreadsheet and it says it is executing normally now but there is no actual post</p>
  <pre><code>function createMeetingMessage(sheet) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var values = ss.getSheetByName(&quot;Post&quot;) .getRange(&quot;B2:D40&quot;).getValues(); // Modify this range, if you want to expand it.
    var message = values.reduce(function(s, e) {
      var SlackIDrow, YearsWorkedrow, Congratsrow, _,
      [SlackIDrow, YearsWorkedrow, Congratsrow, _, _, ] = e;
      if (SlackIDrow &amp;&amp; YearsWorkedrow &amp;&amp; Congratsrow) {
        s += &quot;&gt; *Human* &quot; +&quot;&lt;&quot;+ SlackIDrow +&quot;&gt;&quot;+&quot;\n&quot;
       + &quot;&gt; *Years worked as of today* &quot; + YearsWorkedrow + &quot;\n&quot;
       + Congratsrow + &quot;\n&quot;
        +&quot;\n&quot;;
      }
      return s;
    }, &quot;&gt; *Today's Workiversaries!*&quot; +&quot;\n&quot;);
    return message;
  }
  
  function triggerSlackWorkaversaryLog(channel, msg) {
   var slackWebhook = &quot;https://hooks.slack.com/services/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&quot;;
    var payload = { &quot;channel&quot;: channel, &quot;text&quot;: msg, &quot;link_names&quot;: 1, &quot;username&quot;: &quot;Time to Partyyyyyy&quot;, &quot;icon_emoji&quot;: &quot;:confetti_ball:&quot; };
   var options = { &quot;method&quot;: &quot;post&quot;, &quot;contentType&quot;: &quot;application/json&quot;, &quot;muteHttpExceptions&quot;: true, &quot;payload&quot;: JSON.stringify(payload) };
  
  Logger.log(UrlFetchApp.fetch(slackWebhook, options));
  }
  
  function notifySlackChannelofWorkaversaries() {
   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Post&quot;);
   if (!sheet.getRange(&quot;B2&quot;).getValue()) return;
  var channel = getChannel();
  
  var msg = createMeetingMessage(sheet);
   triggerSlackWorkaversaryLog(channel, msg);
  }
  
  function isTest() {
   return false;
  }
  
  function getChannel() {
   if(isTest()) {
   return &quot;intergration_tests&quot;;
   } else {
   return &quot;intergration_tests&quot;;
   }
  }
  </code></pre>