title: How to read html code in order to grab data with excel vba
body: <p>I'm trying to grab som data from a webpage with Excel VBA.</p>
  
  <p>The HTML code is:</p>
  
  <pre><code>&lt;div id="PriceLabel" class="skuPrice formRow"&gt;
    &lt;span class="skuPriceWrp"&gt;
      &lt;strong class="price red" id="skuPriceLabel" style="font-size: 20px;"&gt; 
         &lt;span class="VAT"&gt;eks mva &lt;/span&gt;&lt;br&gt;
         &lt;span itemprop="price" id="SkuPriceUpdate"&gt;kr 
           &lt;span itemprop="priceCurrency" content="NOK"&gt;151,20&lt;/span&gt;
         &lt;/span&gt; 
       &lt;/strong&gt;
       &lt;span&gt; /
         &lt;span class="UOM" telephone="no"&gt;RL
         &lt;/span&gt;
       &lt;/span&gt;
    &lt;/span&gt;
                          &lt;span class="skuUOMWrp"&gt;
                              &lt;span id="showEachPrice" class="clear"&gt;&lt;/span&gt;
                          &lt;/span&gt;
                          &lt;div class="formRow clear" id="divSkuSavePrice"&gt;
                              &lt;span id="divSkuWhenYouBuy"&gt;
                                  &lt;span class="whenYouSave"&gt;&lt;/span&gt;&amp;nbsp;
                              &lt;/span&gt;
  
                          &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>What i want to grab is the value <code>151,20</code>, located on the first "span".</strong></p>
  
  <p>I've tried: <code>.document.getElementById("skuPriceLabel").getElementsByTagName("span")(0).innerText</code></p>
  
  <p>This gives the value "Eks mva" sometimes, and runtime error 424 (object required) at other times.</p>
  
  <p>I've tried using <code>.document.getElementById("skuPriceLabel").getElementsByTagName("span")(1).innerText</code> 
  and
  <code>.document.getElementById("skuPriceLabel").getElementsByTagName("span")(2).innerText</code>
  as well, but those give the 424 runtime error.</p>
  
  <p>Can somebody please give show me how to read the html code so i can see the logic and know what to look for and write the next time?</p>
  
  <p>My full code is</p>
  
  <pre><code>Sub get_data_2()
  'Source for this code is:
  'http://stackoverflow.com/questions/26613043/get-data-out-of-a-webpage-with-vba
  
  Dim ie As Object
  Dim sht As Worksheet
  Dim SKU As String
  Dim RowCount As Long
  
  Set sht = Sheet8
  Set ie = CreateObject("InternetExplorer.application")
  
  RowCount = 1
  'This just gives the columns a titel i row numer 1.
  sht.Range("a" &amp; RowCount) = "SKU" 'Column A is populated with SKU's to be looked up.
  sht.Range("n" &amp; RowCount) = "Price" 'Column N will be given the price of the SKU.
  
  
  With ie
      .Visible = True
      .navigate "http://www.staples.no/"
  
  Do While .Busy Or _
      .readyState &lt;&gt; 4
      DoEvents
  Loop
  
  Do
      RowCount = RowCount + 1
      SKU = sht.Range("a" &amp; RowCount).Value
  
      With ie 'fill in the searchbox and submit.
          ie.document.all("searchKeywords").Value = SKU 'we can use 491215 as a SKU for this example.
          ie.document.forms("searchForm").submit
  
          Do While .Busy Or _
              .readyState &lt;&gt; 4
              DoEvents
          Loop
  
          'write the price to column N
          sht.Range("n" &amp; RowCount).Value = ie.document.getElementById("skuPriceLabel").getElementsByTagName("span")(1).getElementsByTagName("span")(0).innerText
  
      End With
  Loop While sht.Range("a" &amp; RowCount + 1).Value &lt;&gt; "" 'Loop as long as column A has a SKU (till end of list).
  End With
  Set ie = Nothing
  
  End Sub
  </code></pre>