title: How do you re-open the active document after calling saveAndClose?
body: <p>I'd like to know how to re-open the <strong>active</strong> document after calling saveAndClose.</p>
  
  <p>I have a Google Docs Add-on (<a href="https://chrome.google.com/webstore/detail/magic-rainbow-unicorns/ganidpeaoklofmlmmlamgngfgjopjido" rel="nofollow noreferrer">Magic Rainbow Unicorns</a>) that changes the font colour of every selected character to a different colour of the rainbow. If the document is really long (e.g. 100 pages) then I see the following error:</p>
  
  <blockquote>
    <p>ScriptError: Too many changes applied before saving document. Please
    save changes in smaller batches using Document.saveAndClose(), then
    reopen the document with Document.openById().</p>
  </blockquote>
  
  <p>As suggested on another <a href="https://stackoverflow.com/a/38786153/1912127">SO answer</a>, I have a counter and am doing a flush after 50000 changes.</p>
  
  <pre><code>      // save &amp; flush changes
        if (rainbowIndex%50000 == 0) {
          DocumentApp.getActiveDocument().saveAndClose();
          // reopen the doc and refresh the selection
          selection = DocumentApp.getActiveDocument().getSelection();
          elements = selection.getRangeElements();
        }
  </code></pre>
  
  <p>However this code doesn't work because whenever I try to modify an element I see the error <code>Document is closed, its contents cannot be updated.</code></p>
  
  <p>I can't use <code>DocumentApp.openById</code> as suggested by the error message because my add-on only has permission for the current doc (<code>@OnlyCurrentDoc</code>).</p>
  
  <p>So what I'd like to know is: if it's possible to re-open the active document after closing it because I don't want to change the permissions on my add-on? If it is possible, which method should I call?</p>