Dear 各位大大
小弟 google 了四處,並參考了別位大大的寫法,要自動抓取 1 年內的股票的歷史價格,問題來了。
一開始程式還能執行,結果今天改了一下,巨集就無法顯示和執行,可以請各位大大幫忙看一下嗎??
因為還是新手,一直顯示不能發行 url ,所以拿掉兩行,但不影嚮運行
Sub stock(seldate As String)
Dim myURL As String
Dim oStream As Object 'ADODB.Stream
Dim WinHttpReq As Object 'XMLHTTP
Dim fileIdx As String
Dim YY As String
Dim MM As String
'fileIdx = seldate
fileIdx = VBA.Format(seldate, "yyyymmdd")
YY = Year(Now)
MM = Month(Now)
'If Val(MM) < 10 Then
'MM = "0" & MM
'End If
For a = 1 To 1 '200
If Range("A" & a).Value <> "" Then
b = a
MsgBox b
End If
Next a
For c = 1 To b
stockid = Range("A" & c)
MsgBox stockid
For d = YY To YY - 1 Step -1
MsgBox d
For e = 0 To 11
If e = MM Then Exit For
MM1 = MM - e
'If Val(MM1) < 10 Then
' MM1 = "0" & MM1
'End If
MsgBox MM1
'Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
'Set WinHttpReq = CreateObject("MSXML2.XMLHTTP")
'With WinHttpReq
' .Open "GET", myURL, False
' .Send
' myURL = .responseText
'End With
' Set oStream = CreateObject("ADODB.Stream")
' With oStream
' .Open
' .Type = 1
' .Write WinHttpReq.responseBody
' fileIdx = ThisWorkbook.Path & "\d" & "MM1" - "stockid" & ".csv"
' On Error Resume Next
' Kill fileIdx
' On Error GoTo 0
' .SaveToFile fileIdx
' .Close
' End With
' Set WinHttpReq = Nothing
'Set oStream = Nothing
Next e
Next d
Next c
End Sub
|