Import Financials from Yahoo
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
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
Dim cls
Set cls = doc.getElementById("Col1-1-Financials-Proxy")
Set HdrCls = cls.getElementsByClassName("D(tbr) C($primaryColor)")
RowNumb = 1
ColNumb = 1
For Each c In HdrCls
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
Set cl = cls.getElementsByClassName("D(tbr) fi-row Bgc($hoverBgColor):h")
RowNumb = 2
ColNumb = 1
For Each c In cl
Application.StatusBar = RowNumb
Sh.Cells(RowNumb, ColNumb).Activate
For Each ch In c.Children
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