標題:
VBA POST 抓證交所 每日收盤行情(全部(不含權證、牛熊證)
[打印本頁]
作者:
yhuang168
時間:
2015-2-1 15:56
標題:
VBA POST 抓證交所 每日收盤行情(全部(不含權證、牛熊證)
試試看~有更好的方法請大家一起討論~
要有工作表 WW..並在 A1 上有日期如 2015/01/05
再建一個工作表 dd...
Sub XL()
Dim wt As Date
wt = Sheets("ww").Range("A1").Value
xt = Format(wt, "E/MM/DD")
gt = Format(wt, "E-MM-DD")
Set XML = CreateObject("Microsoft.XMLHTTP")
Set stream = CreateObject("ADODB.stream")
Dim path As String, thePOSTdata, URL
path = "C:\"
Set sh = Sheets("dd")
Sheets("dd").Activate
Worksheets("dd").UsedRange.Offset(0).Clear
URL = "http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/MI_INDEX.php"
thePOSTdata = "download=csv&qdate=" & xt & "&selectType=ALLBUT0999"
XML.Open "POST", URL, 0
XML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XML.send thePOSTdata
With stream
.Open
.Type = 1
.write XML.responseBody
If Dir(path & "收盤" & gt & ".csv") <> "" Then Kill (path & "收盤" & gt & ".csv")
.SaveToFile (path & "收盤" & gt & ".csv")
.Close
End With
With Workbooks.Open(path & "收盤" & gt & ".csv")
.Sheets(1).UsedRange.Offset(117, 0).Copy sh.[a1]
.Close 0
End With
End Sub
作者:
vavashop
時間:
2015-2-11 15:37
我也蠻想知道的
怎麼不用一個網頁有這些資料就好了 用網頁抓
真是 煩死了
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)