私は、特定の日に特定の会社の株価を取得する小さなExcel VBAマクロを持っています。会社は株式シンボル(AutoZoneでは「AZO」、Wal-Martでは「WMT」など)を渡すことで指定され、日付は隣接セルから取得された実際の日付値です。Excel VBAマクロが動作しなくなった(http.Sendの可能性のある問題)
これは2.5年の間美しく働いていますが、今週は何も変えなかったが、今週は仕事が止まった。マクロが値を返す必要があるところで、今は#VALUE!を返すだけです。コードをステップ実行すると、.Send()が終了するまですべてが正常に動作しています。エラーメッセージや何が間違っているかのヒントはなく、実行が終了したように完全に停止します。私はOn Error節を追加しようとしましたが、ヒットしません。注:私はそれが違いをもたらさないと思っていますが、もともと私は括弧なしのhttp.Sendを持っていましたが、( "")を使ってたくさんの例を見ましたので追加しましたが、効果がないようです。
私のVBAエクスペリエンスは非常になので、誰かが私を正しい方向に向けることができればと願っていました。
CODE:
Function StockQuote(strTicker As String, Optional dtDate As Variant)
' Date is optional - if omitted, use today. If value is not a date, throw error.
If IsMissing(dtDate) Then
dtDate = Date
Else
If Not (IsDate(dtDate)) Then
StockQuote = CVErr(xlErrNum)
End If
End If
Dim dtPrevDate As Date
Dim strURL As String, strCSV As String, strRows() As String, strColumns() As String
Dim dbClose As Double
dtPrevDate = dtDate - 7
' Compile the request URL with start date and end date
strURL = "http://ichart.finance.yahoo.com/table.csv?s=" & strTicker & _
"&a=" & Month(dtPrevDate) - 1 & _
"&b=" & Day(dtPrevDate) & _
"&c=" & Year(dtPrevDate) & _
"&d=" & Month(dtDate) - 1 & _
"&e=" & Day(dtDate) & _
"&f=" & Year(dtDate) & _
"&g=d&ignore=.csv"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", strURL, False
http.Send ("")
strCSV = http.responseText
' The most recent information is in row 2, just below the table headings.
' The price close is the 5th entry
strRows() = Split(strCSV, Chr(10)) ' split the CSV into rows
strColumns = Split(strRows(1), ",") ' split the relevant row into columns. 1 means 2nd row, starting at index 0
dbClose = strColumns(4) ' 4 means: 5th position, starting at index 0
StockQuote = dbClose
Set http = Nothing
End Function
'Yahoo'は、21世紀に到着し、今で暗号化された' HTTP'使用しているようだ - 'HTTPS'を。 'strURL =" https://ichart.finance.yahoo.com/table.csv?s= "&strTicker&_'を試してみてください... –
文字通り1文字はすべての数字を修正します。助けてくれてありがとう! – jheaton3