- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2013-7-18 07:38
| 只看該作者
回復 1# t8899
試試看- Option Explicit
- Sub Ex_匯入Table()
- Dim i As Integer, S As Integer, K As Integer, J As Integer
- Dim Element
- With CreateObject("InternetExplorer.Application")
- '.Visible = True '可顯示網頁
- .Navigate "http://newmis.twse.com.tw/stock/group.jsp?ex=tse&ind=TIDX#STATISTICS"
- Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
- Set Element = .document.getelementsbytagname("table")
- On Error Resume Next
- With Sheets(1)
- .Cells.Clear
- 'For s = 0 To element.Length - 1 '不知此網頁的table內容:請先行測試網頁的完整table內容
- For S = 0 To 3 '已找出網頁的table內容在 0-3 中
- For i = 0 To Element(S).Rows.Length - 1
- K = K + 1
- For J = 0 To 5 '資料的欄位共6位
- .Cells(K, J + 1) = Element(S).Rows(i).Cells(J).innerText
- '********************************************
- '不知此網頁的table內容:先行列出 table 位置 *
- 'Sheets(2).Cells(k, J + 1) = s '*
- '********************************************
- Next
- Next
- Next
- .Cells.EntireColumn.AutoFit '自動調整欄寬
- .Cells.EntireRow.AutoFit '自動調整列高
- End With
- .Quit
- End With
- Set Element = Nothing
- MsgBox "0K"
- End Sub
複製代碼 |
|