我是雅虎財經API難民(他們停止他們的API服務)嘗試切換到阿爾法華帝。 我修改了以前用於Yahoo Finance的以下代碼,但我在Excel中遇到了#VALUE錯誤。阿爾法華帝:使用Excel VBA拉從CSV文件中的數據
以下作品的網址本身(它會打開一個CSV如果你輸入到你的網頁瀏覽器),所以我想我真正的問題在於提取的CSV正確的數據到我的Excel電子表格。任何人都可以提供幫助嗎?
我試圖從CSV提取第2行,第5列數據(最後的收盤價)。提前謝謝了!
Function StockClose(Ticker As String)
Dim URL As String, CSV As String, apikey As String, SCRows() As String, SCColumns() As String, pxClose As Double
apikey = "*censored*"
URL = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" & Ticker & "&outputsize=full&" & apikey & "&datatype=csv"
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", URL, False
xmlhttp.Send
CSV = xmlhttp.responseText
'split the CSV into rows
SCRows() = Split(CSV, Chr(10))
'split the relevant row into columns. 0 means 1st row, starting at index 0
SCColumns() = Split(SCRows(1), ",")
'6 means: 5th column; starting at index 0 - price close is in the 5th column
pxClose = SCColumns(6)
StockClose = pxClose
Set http = Nothing
End Function
樣本數據的返回,如果我提取JSON而不是CSV:
{ 「元數據」:{ 「1信息」:「每日價格(開盤,高,低,「關閉」和「卷」 「2.符號」:「SGD = X」, 「3.最後刷新」:「2017-11-10」, 「4.輸出尺寸」:「全尺寸」, 「5.時區」:「美國/東部」 }, 「時間序列(每日)」:{ 「201 7-11-13「:{ 」1。打開「:」1.3588「, 」2。高「:」1.3612「, 」3。低「:」1.3581「, 」4。關閉「:」1.3587「, 」5。體積「:」0「 }, 」2017-11-10「:{ 」打開「:」1.3588「, 」2。高「:」1.3612「, 」3。低「:」1.3581「, 」4。關閉「:」1.3587「, 」5。卷「:‘0’ },
檢查[這個答案](https://stackoverflow.com/a/43969543/2165759),它可以幫助你與雅虎財經的API來管理。 – omegastripes