- 帖子
- 766
- 主題
- 256
- 精華
- 0
- 積分
- 1035
- 點名
- 0
- 作業系統
- windows 11
- 軟體版本
- OFFICE2021
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2011-5-30
- 最後登錄
- 2026-10-2
|
18#
發表於 2014-1-14 14:57
| 只看該作者
回復 t8899
一直出現"ok"訊息視窗?? 你是中學生應該會關閉這"ok"視窗.有問題試著自己解決,VBA才會進步. ...
GBKEE 發表於 2014-1-14 13:50 
我改了一下,是否跟這有關??(紅色部份)
Sub timestock()
Application.ScreenUpdating = False
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")
With Sheets("SHEET5")
' .Cells.Clear
.Range("A1:F17").ClearContents
'For s = 0 To element.Length - 1 '不知此網頁的table內容:請先行測試網頁的完整table內容
For S = 2 To 3 '已找出網頁的table內容在 0-3 中
For i = 0 To Element(S).Rows.Length - 1
K = K + 1
' For j = 0 To Element(S).Rows(i).Cells.Length - 1 '資料的欄位共6位
j=2
.Cells(K, j + 1) = Element(S).Rows(i).Cells(j).innerText
Next
' Next
Next
' .Cells.EntireColumn.AutoFit '自動調整欄寬
' .Cells.EntireRow.AutoFit '自動調整列高
End With
.Quit
End With
Set Element = Nothing
' MsgBox "0K"
End Sub |
|