title: VBA: How to wait for page to load
body: <p>I'm in the middle of writing a script for signing into a form, and filling in a bunch of "sign up" information and clicking submit.</p>
  
  <p>Thus far, i have managed to get the script to navigate to the sign in page, enter username, enter password and click "sign in".</p>
  
  <p>However, whilst I would normally use the "While IE.readyState &lt;> 4 Or IE.Busy: DoEvents: Wend" function to wait for the next page to load, i am having trouble because unfortunately what appears to be happening is that once the sign in button is clicked, the URL is redirected to about 2 interim "loading" pages/URLs before arriving at the "enter details" page/URL.</p>
  
  <p>This results in a run-time 13 error, as the script thinks the page has already loaded, despite the browser then moving on to the final/correct page.</p>
  
  <p>Here is the code in question:</p>
  
  <pre><code>While IE.readyState &lt;&gt; 4 Or IE.Busy: DoEvents: Wend
  
      Set UserN = IE.document.getElementByID("login_username")
      UserN.Value = "exampleUser"
  
      Set PassW = IE.document.getElementByID("login_entered_password")
      PassW.Value = "ExamplePass"
  
      Set AllHyperLinks = IE.document.getElementsByClassName("label-content")
       For Each hyper_link In AllHyperLinks
           If hyper_link.innerHTML = "Sign in" Then
               hyper_link.Click
               Exit For
           End If
       Next
  
      While IE.readyState &lt;&gt; 4 Or IE.Busy: DoEvents: Wend
      Set Fname = IE.document.getElementByID("firstname")
      Fname.Value = "John"
  
  End Sub
  </code></pre>
  
  <p>Essentially the script loads the page>enters username>enters password>clicks sign in>is supposed to wait until the final url is loaded>enters first name in the first name field (after this is working i will write the remainder of the script for entering details.</p>
  
  <p>Any and all help would be amazing!
  thanks all</p>