title: VBA - Addressing Internet Explorer tabs
body: <p>Strangely enough I didn't find any information on the topic and I'm currently stuck at the point where I managed to open a new tab in an instance of IE by programmatically clicking a button, but I haven't the faintest clue of how to address the new tab in order to get information from there (the button basically brings up a new tab with the result of a search).</p>
  
  <p>This is basically a straightforward question, but I'm including my code anyway:</p>
  
  <pre><code>Sub AddInfoFromIntranet()
  
  Dim Ie As SHDocVw.InternetExplorer
  Dim URL As String
  Dim iFrames As MSHTML.IHTMLElementCollection
  Dim iFrame As MSHTML.HTMLFrameElement
  Dim Doc As MSHTML.HTMLDocument
  Dim InputBox As MSHTML.IHTMLElementCollection, htmlButton, allTags, Tag
  
  ' Opens Intranet - yeah, sadly it's not a public web page
  URL = "{My intranet website}"
  Set Ie = New SHDocVw.InternetExplorer
  With Ie
      .navigate URL
      .Visible = True
      While .Busy Or .readyState &lt;&gt; READYSTATE_COMPLETE: DoEvents: Wend
      Set Doc = .document
  End With
  
  ' Gets top_window frame and navigates to it, then inserts the name to search
  Set iFrames = Doc.getElementsByName("top_window")
  If Not iFrames Is Nothing Then
  
      Set iFrame = iFrames(0)
      Ie.navigate URL &amp; iFrame.src
  
      While Ie.Busy Or Ie.readyState &lt;&gt; READYSTATE_COMPLETE: DoEvents: Wend
      Set InputBox = Doc.getElementsByName("Nachnamevalue")
      If Not InputBox Is Nothing Then InputBox(0).Value = "test"
  
      ' Clicks on "search"
      Set allTags = Doc.getElementsByTagName("input")
      For Each Tag In allTags
          If Tag.Value = "suchen" Then 
              Tag.Click
              Exit For
          End If
      Next
  
      ' Here a new tab is opened, must find info in this tab
      While Ie.Busy Or Ie.readyState &lt;&gt; READYSTATE_COMPLETE: DoEvents: Wend
  
      ' HERE I HAVE NO CLUE WHAT TO WRITE. THE CODE ABOVE WORKS FLAWLESSLY
  
  End If
  
  Set Doc = Nothing
  Set iFrames = Nothing
  Set iFrame = Nothing
  Set InputBox = Nothing
  Set allTags = Nothing
  Set Ie = Nothing
  
  Ie.Quit
  
  End Sub
  </code></pre>
  
  <p>Now, is there a way to address a tab by: 1) its name (and where do I find it) 2) its position in browser 3) the status (if it is "active") ?</p>
  
  <p>Bonus questions: since I am new to VBA and Internet Explorer interaction, what exactly are the variables: <code>htmlButton, allTags, Tag</code> ? Also, could anyone explain if I need to set all the variables at the end to nothing, or I just need to set the Internet Explorer to nothing?</p>
  
  <p>Thanks in advance!</p>