[英]Why my yahoo finance url not working for querytables.add connection from web
I'm trying to create a worksheet that can retrieve historical stock data from yahoo finance.我正在尝试创建一个可以从 yahoo Finance 检索历史股票数据的工作表。 The code works six or seven months ago without 365 subscription.
该代码在 6 或 7 个月前有效,无需 365 订阅。 And I found it's not working now.
我发现它现在不起作用。 Here is my code:
这是我的代码:
Sub Button4_Click()
Dim DataSheet As Worksheet
Dim EndDate As Date
Dim StartDate As Date
Dim Symbol As String
Dim qurl As String
Dim SD As String
Dim ED As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Set DataSheet = ActiveSheet
StartDate = DataSheet.Range("B1").Value
EndDate = DataSheet.Range("B2").Value
Symbol = DataSheet.Range("B3").Value
Range("C7").CurrentRegion.ClearContents
SD = DateDiff("s", "1/1/1970", StartDate)
ED = DateDiff("s", "1/1/1970", EndDate)
qurl = "https://query1.finance.yahoo.com/v7/finance/download/" & Symbol & "?period1=" & SD & "&period2=" & ED & "&interval=1d&events=history&includeAdjustedClose=true"
With DataSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("C7"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Range("C7").CurrentRegion.TextToColumns Destination:=Range("C7"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, other:=False
Range(Range("C7"), Range("C7").End(xlDown)).NumberFormat = "mmm d/yy"
Range(Range("D7"), Range("G7").End(xlDown)).NumberFormat = "0.00"
Range(Range("H7"), Range("H7").End(xlDown)).NumberFormat = "0.00"
Range(Range("I7"), Range("I7").End(xlDown)).NumberFormat = "0,000"
'Worksheets("Grab data").Range("C7:xlDown").Select
Application.Calculation = xlCalculationAutomatic
End Sub
The error keeps showing as:错误一直显示为:
Unable to open the url.无法打开 url。 And the internet cannot return the object you requested.
并且互联网无法返回您请求的 object。
Thank you very much for any help!非常感谢您的帮助!
Found out that this code works on mac(without a 365 subscription) but not wondows.发现此代码适用于 mac(没有 365 订阅)但不适用于 wandows。 Windows with a 365 subscription can just use the web query to get it quick.
订阅 365 的 Windows 只需使用 web 查询即可快速获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.