Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

vba - Excel not extracting table of historical stock prices from Yahoo Finance

I'm attempting to extract a table of historical stock prices to bring into a an Excel worksheet. I'm currently using Excel for Mac so activex / com objects are not supported, which is why I have had to go this route. If I use a different URL it extracts the table information just fine, and visiting the URL directly in browser works fine, but if I try to extract historical price information Excel throws a VB error 1004.

HistoryURL = "URL:https://finance.yahoo.com/quote/AAPL/history?period1=1577836800&period2=1609459200&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true"
        
With .QueryTables.Add(Connection:=HistoryURL, Destination:=.Range("Z1"))
             .FillAdjacentFormulas = False
             .PreserveFormatting = True
             .RefreshOnFileOpen = False
             .BackgroundQuery = True
             .RefreshStyle = xlOverwriteCells
             .SavePassword = False
             .SaveData = False
        End With

What am I missing here?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Couldn't find a suitable way to do this with VBA so I enabled the Beta Channel updates for Excel which allowed me to start using the native StockHistory function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...