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://mis.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