雅虎历史报价在Excel中 - 继续

问题描述 投票:0回答:1

我看到雅虎博客上的说明声明他们已经停止支持iChart,我看到这个答案Yahoo Finance Historical data downloader url is not working讨论了历史数据的新请求格式。

这是我用来下载历史数据的原始代码片段(它是在每个股票代码的电子表格中创建标签的循环的一部分)

With Sheets(SheetName).QueryTables.Add(Connection:="URL;http://ichart.finance.yahoo.com/table.csv?s=" & yahoosymbols & "&a=09&b=29&c=1984&d=04&e=12&f=2020&g=w&ignore=.csv", Destination:=DestinationRange)
        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        .SaveData = False
        .FieldNames = False
    End With

这是使用新版本URL的新代码

With Sheets(SheetName).QueryTables.Add(Connection:="URL;http://query1.finance.yahoo.com/v7/finance/download/" & yahoosymbols & "?period1=947570400&period2=1577858400&interval=1wk&events=history&crumb=RhdXrQKrUXZ", Destination:=DestinationRange)
        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        .SaveData = False
        .FieldNames = False
    End With

如果我复制并粘贴网址(为yahoosymbols变量添加股票代码),那么它在浏览器中工作正常。

但是,当我运行此代码时,我得到一个excel 1004错误,并说它无法打开该URL

有什么想法吗?我不是VBA的家伙,所以可能会犯一个真正的业余错误。谢谢

excel vba excel-vba yahoo-api yahoo-finance
1个回答
0
投票

您使用的网址不再有效。但既然你不是一个vba人,而你只需要在Excel中使用YF数据,为什么不使用Deriscope Excel插件?免责声明:我是Deriscope的作者。

© www.soinside.com 2019 - 2024. All rights reserved.