title: Excel VBA extracting href value
body: <p>I have a macro that tries to extract all the href values from a page but it only seems to get the first one. If someone could help me out that would be greatly appreciated.</p>
  
  <p>The URL I used is <a href="https://www.facebook.com/marketplace/vancouver/entertainment" rel="nofollow noreferrer">https://www.facebook.com/marketplace/vancouver/entertainment</a></p>
  
  <p><a href="https://i.stack.imgur.com/9OCho.png" rel="nofollow noreferrer">Screenshot of HTML</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="_3-98" data-testid="marketplace_home_feed"&gt;
    &lt;div&gt;
      &lt;div&gt;
        &lt;div class="_65db"&gt;
            &lt;a class="_1oem" href="/marketplace/item/920841554781924" data-testid="marketplace_feed_item"&gt;
            &lt;a class="_1oem" href="/marketplace/item/580124349088759" data-testid="marketplace_feed_item"&gt;
            &lt;a class="_1oem" href="/marketplace/item/1060730340772072" data-testid="marketplace_feed_item"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>    Sub Macro1()
  ``marker = 0
  Set objShell = CreateObject("Shell.Application")
  IE_count = objShell.Windows.Count
  For x = 0 To (IE_count - 1)
      On Error Resume Next    ' sometimes more web pages are counted than are open
      my_url = objShell.Windows(x).document.Location
      my_title = objShell.Windows(x).document.Title
  
      If my_title Like "Facebook" &amp; "*" Then 'compare to find if the desired web page is already open
          Set ie = objShell.Windows(x)
          marker = 1
          Exit For
      Else
      End If
  Next
  
  Set my_data = ie.document.getElementsByClassName("_3-98")
  Dim link
  i = 1
  For Each elem In my_data
      Set link = elem.getElementsByTagName("a")(0)
      i = i + 1
  
       'copy the data to the excel sheet
      ActiveSheet.Cells(i, 4).Value = link.href
  
  Next
  
  End Sub
  </code></pre>