返回列表 上一主題 發帖

[發問] 現在要如何到證交所下載外資成交資訊

[發問] 現在要如何到證交所下載外資成交資訊

之前是用下列的程式碼 到 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

OK 了.... 謝謝指導

TOP

        靜思自在 : 生氣,就是拿別人的過錯來懲罰自己。
返回列表 上一主題