Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

How to pull financial statements from Yahoo Finance (2019 URL) in VBA

$
0
0

I copied the code from this link Extract financial fundamental from Yahoo finance with excel

The code from ASH works to pull balance sheet data; however, when I change the ticker (like MSFT), it begins pulling in the wrong data.

  1. Why is it pulling in different data points than when I switch the ticker in the URL Link?
  2. How can I go about correcting it?

    Sub Yahoo_BS()
    
    Dim xmlHttp As Object
    Dim TR_col As Object, Tr As Object
    Dim TD_col As Object, Td As Object
    Dim row As Long, col As Long
    
    Set xmlHttp = CreateObject("MSXML2.XMLHTTP.6.0")
    myURL = "https://finance.yahoo.com/quote/SBUX/balance-sheet?p=SBUX"
    xmlHttp.Open "GET", myURL, False
    xmlHttp.setRequestHeader "Content-Type", "text/xml"
    xmlHttp.send
    
    Dim html As Object
    Set html = CreateObject("htmlfile")
    html.body.innerHTML = xmlHttp.responseText
    
    Dim tbl As Object
    Set tbl = html.getElementById("Pos(r)")
    
    
    row = 1
    col = 1
    
    Set TR_col = html.getElementsByTagName("TR")
    For Each Tr In TR_col
        Set TD_col = Tr.getElementsByTagName("TD")
        For Each Td In TD_col
            Cells(row, col) = Td.innerText
            col = col + 1
        Next
        col = 1
        row = row + 1
    Next
    
    End Sub
    

Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>