Option Explicit
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")
On Error Resume Next
With Sheets("sheet5")
.Cells.CLEAR
'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 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
[attach]17246[/attach]作者: t8899 時間: 2014-1-13 15:35
一直出現"ok"訊息視窗是套入我的巨集的一段
For i = 1 To 10
Dim aaa As Variant
aaa = Sheets("Sheet5").Range("C3")
If IsNumeric(aaa) Then Exit For
If Not IsNumeric(aaa) Then Run "timestock"
Next作者: 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作者: GBKEE 時間: 2014-1-14 15:31
循還的範圍
.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("SHEET1")
.Cells.Clear
K = 0
'For s = 0 To element.Length - 1 '不知此網頁的table內容:請先行測試網頁的完整table內容
For S = 2 To 2 '已找出網頁的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作者: GBKEE 時間: 2014-1-15 16:31
Dim i As Integer, S As Integer, K As Integer, j As Integer
Dim Element
Dim RNG
If Sheet3.Range("K1").Value = 1 Then Set RNG = #12:01:00 AM#
If Sheet3.Range("K1").Value = 2 Then Set RNG = #12:02:00 AM#
If Sheet3.Range("K1").Value = 3 Then Set RNG = #12:00:30 AM#
If Sheet3.Range("K1").Value = 4 Then Set RNG = #12:00:10 AM#
Dim i As Integer, S As Integer, K As Integer, j As Inte ...
t8899 發表於 2014-1-15 20:36
抱歉,打擾.......已解決....................
If Sheet3.Range("K1").Value = 1 Then Application.OnTime Time + #12:01:00 AM#, "timestock"
If Sheet3.Range("K1").Value = 2 Then Application.OnTime Time + #12:02:00 AM#, "timestock"
If Sheet3.Range("K1").Value = 3 Then Application.OnTime Time + #12:00:30 AM#, "timestock"
If Sheet3.Range("K1").Value = 4 Then Application.OnTime Time + #12:00:10 AM#, "timestock"作者: t8899 時間: 2014-1-16 05:59
回復 t8899
此網頁的程式碼
GBKEE 發表於 2014-1-13 17:40
是否少了 Set Element = Nothing 這一行??
應插在34或36行前面??作者: GBKEE 時間: 2014-1-16 07:25