- 帖子
- 41
- 主題
- 8
- 精華
- 0
- 積分
- 64
- 點名
- 0
- 作業系統
- WIN7
- 軟體版本
- OFFICE2010
- 閱讀權限
- 20
- 註冊時間
- 2015-3-11
- 最後登錄
- 2020-10-7
|
之前是用下列的程式碼 到 http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U.php 這邊去下載每日外資買賣超資訊。
原本都沒有問題,但一月份 證交所改網頁,原本可以看到一個下載路徑,但現在沒辦法看到,導致不知道該如何下載每日的 CSV 檔...
有沒有人知道該如何下載?
Dim st
Dim myURL As String
Dim oStream As Object 'ADODB.Stream
Dim WinHttpReq As Object 'XMLHTTP
Dim fileidx As String
Dim seldate As String
Worksheets("Config").Select
endline = Range("A65536").End(xlUp).Row
seldate = Range("A" & i).Value ''成交日期
fileidx = seldate
''http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U_print.php?edition=ch&filename=genpage/A20141202.dat&type=csv
myURL = "http://www.twse.com.tw/ch/trading/fund/TWT38U/TWT38U_print.php?edition=ch&filename=genpage/A" & _
fileidx & ".dat&type=csv"
''外資買賣資訊
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 = Sheets("Config").Range("G2") & "\A" & fileidx & ".csv" ''設定下載路徑及檔名
On Error Resume Next
Kill fileidx
On Error GoTo 0
.SaveToFile fileidx
.Close
End With
Set WinHttpReq = Nothing
Set oStream = Nothing
End Sub |
|