title: VBA IE Automation - Read iFrame
body: <p>Our business uses a browser-based program for operations. I'm automating a solution to navigate through this site, and retrieve some data at the end.</p>
  
  <p>The site itself uses regular frames very heavily. However, at the very end of my process, it populates my data not into a frame, but an iFrame. There's also very extensive javascript throughout the site, making things muddy.</p>
  
  <p>Grabbing the iFrame's src URL and opening in a new browser errors out the page (i.e. the page displays error text instead of the content). </p>
  
  <p><strong>My question:</strong> </p>
  
  <p>How can I grab the text out of an iFrame through VBA?</p>
  
  <p><strong>What I've tried so far</strong> <em>(feel free to skip)</em>:</p>
  
  <p><em>Target a specific iFrame in a specific frame, and grab innerHTML</em></p>
  
  <pre><code>With ie.document.frames(myFrameNum).document.getElementsByTagName("iframe")(1).document.body
  stringResult = .innerHTML
  </code></pre>
  
  <p><em>Target a specific iFrame by ID in a specific frame, and grab innerHTML</em></p>
  
  <pre><code>Dim iFrm As HTMLIFrame
  Set iFrm = ie.document.frames(myFrameNum).document.getElementByID("iFrameID")
  Debug.Print iFrm.document.body.innerText
  </code></pre>
  
  <p><em>Find any instances of iFrames, and grab them</em> (No results - perhaps because the iframe is embeded in a frame?)</p>
  
  <pre><code>Dim iFrm As HTMLIFrame
  Dim doc As HTMLDocument
   For iterator = 0 To ie.document.all.Length - 1
    If TypeName(ie.document.all(iterator)) = "HTMLIFrame" Then
     Set iFrm = ie.document.all(iterator)
     Set doc = iFrm.document
     Debug.Print &amp; doc.body.outerHTML
    End If
  Next
  </code></pre>