- 帖子
- 219
- 主題
- 24
- 精華
- 0
- 積分
- 243
- 點名
- 0
- 作業系統
- Windows10
- 軟體版本
- Office2016
- 閱讀權限
- 20
- 性別
- 女
- 註冊時間
- 2012-4-18
- 最後登錄
- 2022-2-7
 
|
32#
發表於 2014-12-17 17:50
| 只看該作者
回復 29# GBKEE
您好,這裡一直出現缺 With 不知道哪裡要修改
麻煩幫忙校正問題- Sub 下載CSV()
- Dim path As String, 日期 As String, URL As String, 代號
- path = "C:\myStock\"
- 日期 = Format(Date, "emmdd")
- Dim Rng As Range
- AA:
- Set Rng = [C:C].Find("NG", , , xlWhole)
- Sheets("下載依據").Activate
- With CreateObject("InternetExplorer.application")
- .Visible = True
- .navigate "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/brokerBS.php?l=zh-tw"
- Do Until .readyState = 4
- DoEvents
- Loop
- 驗證碼 = InputBox("輸入查詢驗證碼", "驗證碼", code) '驗證碼 = InputBox
- For Each 代號 In Range(Rng.Offset(0, -2), [E65536].End(xlUp))
- .document.all("stk_code").Value = 代號
- .document.all("auth_num").Value = 驗證碼
- '**** 直接下載CSV ****
- Dim xml As Object
- Dim stream
- Set xml = CreateObject("Microsoft.XMLHTTP")
- Set stream = CreateObject("ADODB.stream")
- 'GET http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/download_ALLCSV.php?curstk=8069&stk_date=1031215&auth=驗證碼
- URL = "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/download_ALLCSV.php?curstk=" & 代號 & "&stk_date=" & 日期 & "&auth=" & 驗證碼
- xml.Open "GET", URL, 0
- xml.send
- With stream
- .Type = 1
- .Open
- .write xml.responseBody
- '**** 判斷讀取資料 ****************************************************************
- If .document.body.Innertext Like "*該日無交易資訊*" Then
- GoTo NN 'Goto 下一個
- ElseIf .document.body.Innertext Like "*驗證碼錯誤,請重新查詢*" Then
- Sheets("下載依據").Range("C:C").Delete '清除舊的NG記號
- 代號.Offset(, 2) = "NG" '新增斷點
- .Quit '關閉 IE 視窗
- GoTo AA
- ElseIf .document.body.Innertext Like "*驗證碼已逾期,請重新查詢*" Then
- Sheets("下載依據").Range("C:C").Delete '清除舊的NG記號
- 代號.Offset(, 2) = "NG" '新增斷點
- .Quit '關閉 IE 視窗
- GoTo AA
- '***** 判斷讀取資料 End *************************************************************
- .SaveToFile (path & 代號 & ".csv")
- .Close
- End With
- NN:
- Next
- .Quit '關閉 IE 視窗
- End With
- Range("C2") = "NG" '重新作記號,方便下回下載
- End Sub
複製代碼 |
|