- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
本帖最後由 GBKEE 於 2016-1-11 14:06 編輯
回復 2# kim223824 - Option Explicit
- Sub Ex_TABLE() '查看大盤歷史資料查詢,資料所在的TABLE
- Dim i As Integer, E As Object, url, xTable, A
- url = "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
- With CreateObject("InternetExplorer.application")
- .Visible = True
- .Navigate url
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- With .Document
- .ALL("myear").Value = "104"
- .ALL("mmon").Value = "12"
- For Each E In .ALL.tags("input")
- If E.Type = "button" And E.Value = "查詢" Then
- E.Click
- Exit For
- End If
- Next
- End With
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Set xTable = .Document.getElementsByTagName("TABLE")
- On Error Resume Next
- For Each E In xTable
- i = i + 1
- Cells(i, 1) = A '查看資料在那一個TABLE
- A = A + 1
- i = i + 1
- Cells(i, "A") = E.innertext
- Next
- .Quit '關閉網頁
- End With
- End Sub
複製代碼- Option Explicit
- Sub 大盤指數20160110()
- Dim xTable As Object, k As Integer, c As Integer, r As Integer
- Dim url As String, i As Integer, E As Object
- 'Sheets("下載").Select
- url = "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
- With CreateObject("InternetExplorer.application")
- .Visible = True
- .Navigate url
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- With .Document
- .ALL("myear").Value = "104"
- .ALL("mmon").Value = "12"
- ' .all("onclick").Click '按下按鍵的
- For Each E In .ALL.tags("input")
- If E.Type = "button" And E.Value = "查詢" Then
- E.Click '按下查詢鍵
- Exit For
- End If
- Next
- End With
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- 'Sub Ex_TABLE() 查看大盤歷史資料查詢,得知資料所在的TABLE
- Set xTable = .Document.getElementsByTagName("TABLE")(10) '資料在這
- With Sheets("下載")
- .UsedRange.Clear
- k = k + 1
- For r = 0 To xTable.Rows.Length - 1
- For c = 0 To xTable.Rows(r).Cells.Length - 1
- .Cells(k, c + 1) = xTable.Rows(r).Cells(c).innertext
- Next
- k = k + 1
- Next
- End With
- .Quit
- End With
- End Sub
複製代碼 |
|