I’m working on a project to automate the extraction of data of how the various stock indices are performing into Excel from Yahoo Finance. But the problem is that all the code and help videos I have found online use Internet Explorer as their search engine, but as it is no longer available, I cannot use their code. Even if I modify the code to use google chrome as the browser, it does not work.
And can the macro be in such a way that It can extract data from multiple webpages at once?
So can anyone help create a code that will extract the historical data of how the multiple stock indices have performed every week in such a way that I can use it to get the data every week by just running the macro?
Just some example links-
https://finance.yahoo.com/quote/INDEX?p=INDEX&.tsrc=fin-srch
https://finance.yahoo.com/quote/VOO?p=VOO&.tsrc=fin-srch
Some codes i found online that might provide a base for it –
2
Answers
VBA might not be the best tool. Anyway, just for fun, i’ve wrote down a really blunt code:
You’ll need the Microsoft XML v6.0 reference.
Credits: the function
HtmlDecode
was created by trincot and published here.Something like this, I think, but the table isn’t being parsed correctly.
Sub ImportStockIndexData()
Dim i As Integer
Dim indexTickers() As Variant
Dim indexData As Variant
Dim dataRange As Range
Remember, under Tools > References, set a reference to ‘Microsoft Internet Controls’.