title: Excel VBA: Wait for JavaScript execution in Internet Explorer
body: <p>I am trying to do some web scraping in Excel VBA. Here is the part of the code that I am having trouble with:</p>
  
  <pre><code>IE.Navigate URL
  Do
    DoEvents
  Loop While IE.ReadyState &lt;&gt; 4 Or IE.Busy = True
  Set doc = IE.document
  </code></pre>
  
  <p>After running this <code>doc</code> contains html that still has unexecuted JavasScript in it.
  This is the signature of the script that has not been executed:</p>
  
  <pre><code>&lt;SCRIPT type=text/javascript&gt;
          goosSearchPage.Initialize(...)...;
  &lt;/SCRIPT&gt;
  </code></pre>
  
  <p>I can wait for execution by doing <code>Application.Wait(Now  + TimeValue(x))</code> but that really is not satisfactory, as the amount of time the script takes to execute is quite variable depending on input.</p>
  
  <p>Is there a way to either wait for the script to finish evaluating or to just evaluate the script directly in the <code>doc</code> object?</p>