I want to download data from here: https://finance.yahoo.com/q/bs?s=MSFT+Balance+Sheet&annual to my Excel file for dozens of stocks. Any tips on how to do this in VBA will be highly appreciated.
FYI!
Mr. G North succeeded to create the code scraping Key Statistics from Yahoo Finance (see below). I need a similar stuff but for Balance Sheet page.
Hi
Here's some code to extract data from the microsoft and cisco pages you refer to using Web Queries. You dont say what info you want from the pages so I picked most of it. You can record defining a basic web query to limit the data to the parts you want. The modify it to include the other aspects of this code.
I only did two good luck with 600.
Sub Macro2()
Dim conString As String
Dim conName As String
Dim txtSymbols(0, 2) As String
txtSymbols(0, 1) = "MSFT"
txtSymbols(0, 2) = "CSCO"
For i = 1 To 2
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = txtSymbols(0, i)
conString = "URL;http://finance.yahoo.com/q/ks?s=" & txtSymbols(0, i) & "+Key+Statistics"
conName = "ks?s=" & txtSymbols(0, i) & "+Key+Statistics"
With ActiveSheet.QueryTables.Add(Connection:=conString, Destination:=Range("$A$1"))
.Name = conName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """yfncsubtit"",8,10,11,13,15,17,19,21,23"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next i
End SubYou can use
ActiveWorkbook.RefreshAll
To refersh the data gathered by these queries
Or
Selection.QueryTable.Refresh BackgroundQuery:=False
to refresh just the query on the current page.
Hope this points you in the right direction.