Import Financials from Yahoo

  • Select the Tiker in D4 Cell
  • Click on Extract Financials\Consolidated Macro Button
  •  

    Consolidated Macro:

     

    Sub ConsolidatedMacro()
    Application.SheetsInNewWorkbook = 1
    Set BtnSh = ActiveWorkbook.Sheets("Sheet2")
    Ticker = BtnSh.Range("D4").Value
    Dim I As Integer
    Dim Link As String

    For I = 1 To 3
    Set IE = New InternetExplorer
    IE.Visible = True
    'https://finance.yahoo.com/quote/AAPL/financials?p=AAPL
    If I = 1 Then
    Link = "https://finance.yahoo.com/quote/" & Ticker & "/financials?p=" & Ticker
    End If

    If I = 2 Then
    Link = "https://finance.yahoo.com/quote/" & Ticker & "/balance-sheet?p=" & Ticker
    End If

    If I = 3 Then
    Link = "https://finance.yahoo.com/quote/" & Ticker & "/balance-sheet?p=" & Ticker
    End If

    IE.navigate Link
    Application.Wait (Now + TimeValue("00:00:23"))
    If I = 1 Then
    Set Wkb = Workbooks.Add
    Set Sh = Wkb.ActiveSheet
    Else:
    Set Sh = Wkb.Sheets.Add(after:=Wkb.Sheets(Sheets.Count))
    End If

    Dim doc As HTMLDocument
    Set doc = IE.document

    'Identify the ID
    Dim cls
    Set cls = doc.getElementById("Col1-1-Financials-Proxy")

    'Identify the Header Class
    Set HdrCls = cls.getElementsByClassName("D(tbr) C($primaryColor)")
    RowNumb = 1
    ColNumb = 1
    For Each c In HdrCls
    'MsgBox c.innerText
    Sh.Cells(RowNumb, ColNumb).Activate
    For Each ch In c.Children
    'MsgBox ch.innerText
    Sh.Cells(RowNumb, ColNumb).Value = ch.innerText
    'MsgBox c.Children(1).innerText
    ColNumb = ColNumb + 1
    Next
    RowNumb = RowNumb + 1
    ColNumb = 1
    Next
    '======Identify the Body class================
    Set cl = cls.getElementsByClassName("D(tbr) fi-row Bgc($hoverBgColor):h")

    RowNumb = 2
    ColNumb = 1
    For Each c In cl
    Application.StatusBar = RowNumb
    'MsgBox c.innerText
    Sh.Cells(RowNumb, ColNumb).Activate
    For Each ch In c.Children
    'MsgBox ch.innerText
    Sh.Cells(RowNumb, ColNumb).Value = ch.innerText
    ColNumb = ColNumb + 1
    Next
    RowNumb = RowNumb + 1
    ColNumb = 1
    Next
    If I = 1 Then
    Sh.Name = "Income Statement"
    End If
    If I = 2 Then
    Sh.Name = "Balance Sheet"
    End If
    If I = 3 Then
    Sh.Name = "CashFlow"
    End If
    Sh.Activate
    ActiveWindow.DisplayGridlines = False

    IE.Quit
    Set IE = Nothing
    FormatActivesheet
    Next
    Application.StatusBar = ""
    MsgBox "Automation Completed"
    Application.SheetsInNewWorkbook = 3

    End Sub

    DownLoad The Workbook