暱稱: joey0415
中學生
- 帖子
- 361
- 主題
- 57
- 精華
- 0
- 積分
- 426
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2003,2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2010-5-13
- 最後登錄
- 2022-12-8
|
13#
發表於 2015-8-14 21:08
| 只看該作者
回復 12# hipper68
你試試看,應該可行!- Sub ex()
- With CreateObject("internetexplorer.application")
- .Visible = True
- .Navigate "http://www.twse.com.tw/ch/trading/exchange/MI_MARGN/MI_MARGN.php"
- Do Until .ReadyState = 4
- DoEvents
- Loop
-
- .Document.getElementById("date-field").Value = "104/08/12" '填入
-
- '---------,內建的fireevent 的onchange失效,改用調用js的方法--------
- Set evt = .Document.createEvent("HTMLEvents")
- evt.initEvent "change", True, False
- Set lst = .Document.all("selectType") 'option的name是selectType,但getElementsByName無法處理,要all才行
- lst.selectedIndex = 0
- lst.dispatchEvent evt
-
- .Document.all("query-button").Click
- Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
- Application.Wait Now + TimeValue("00:00:5")
- ' Stop
-
- ' For Z = 0 To 10
- ' MsgBox .Document.getElementsByTagName("table")(Z).innerText
- ' Next
- Stop
- Set hTable = .Document.getElementsByTagName("table")(3) '第4個table
- ' tt = hTable.Rows.Length
- ' qq = hTable.Rows(2).Cells.Length
- With ActiveSheet
- For i = 1 To hTable.Rows.Length - 1 '前3個是標題與空白跳過
- For j = 0 To hTable.Rows(i).Cells.Length - 1
- .Cells(i, j + 1) = hTable.Rows(i).Cells(j).innerText
- Next
- Next
- End With
- .Quit
- ' MsgBox "OK"
- End With
-
- End Sub
複製代碼 |
|