title: In Excel VBA, what is the way to check if the web page is fully loaded?
body: <p>To pause code until a web page is fully loaded, I've been using the method below with great success almost all of the time.</p>
  
  <pre><code>Do While objIE.Busy = True Or objIE.readyState &lt;&gt; 4: DoEvents: Loop
  </code></pre>
  
  <p>But occasionally, I see text content load after the method determines that the page is fully loaded, and so that content is not extracted.</p>
  
  <p>However, if I step through the code via F8, the content is extracted every time. This is done about as fast as I can press the F8 key repeatedly.</p>
  
  <p>So how can I check to ensure the page, and all its content, is fully loaded before the code continues to extract data?</p>
  
  <p>In both cases, IE is running invisibly. However, I've tried this with IE visible and there is actually content in this specific location on the pages I'm working with.</p>
  
  <p>This is being done in Excel 2016, using VBA script. The specific content request is written like:</p>
  
  <pre><code> 'get item name from page and write it to the first cell on the first empty row available
   Set itemName = objIE.document.querySelector(".the-item-name")
   Worksheets("Results").Range("A1048576").End(xlUp).Offset(1, 0).Value = itemName.innerText
  </code></pre>
  
  <p>I've read through <a href="https://stackoverflow.com/questions/13029708/excel-vba-wait-for-javascript-execution-in-internet-explorer">Excel VBA: Wait for JavaScript execution in Internet Explorer</a> because I think that maybe the values are getting added after the document is loaded, in an effort to prevent anyone from scraping data. However, I can't seem to identify any script that may be doing that. Doesn't mean it isn't there. I just can't see it yet.</p>
  
  <p>A specific example of the page with this issue is URL</p>
  
  <p><a href="https://www.homedepot.ca/en/home/p.dry-cloth-refills-32---count.1000660019.html" rel="nofollow noreferrer">https://www.homedepot.ca/en/home/p.dry-cloth-refills-32---count.1000660019.html</a></p>
  
  <p>Initially <code>product-total-price</code> div element contains dash (-), prior to the price being loaded, so that's what the request will return: <code>- / each</code> instead of <code>$11.29 / each</code>.</p>
  
  <p>I have a workaround, but it's not as efficient or as concise as I'd like it to be. I test the string returned for the presence of the dash. If it's there, loop and check it again, else capture it and insert it into the worksheet.</p>
  
  <pre><code>setPriceUM:
      Set hdPriceUM = objIE.document.querySelector(".product-total-price").innerTe‌​‌​xt
      hdPriceUMString = hdPriceUM.innerText
      stringTest = InStr(hdPriceUMString, "-")
      If stringTest = True Then
          GoTo setPriceUM
      Else
          Debug.Print hdPriceUMString
      End If
  </code></pre>
  
  <p>Thank you for taking the time to read this and consider it.</p>