Sub Macro1()
Dim i As Integer, j As Integer, k As Integer
URL$ = "http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php"
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate URL
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
.Document.all("input_stock_code").Value = 6121 '要查的代碼
.Document.all(1758).Click <=====巨集執行到此就錯誤,請問這一行是為何意,找了很久查不出是何意
Application.Wait Now + TimeValue("00:00:02") '等待2秒更新資料
Set tmp = .Document.getelementsbytagname("table")(79) <==== (79)又是何意??
k = 1
Cells(k, 1) = tmp.Rows(0).innertext
Cells(k, 1).WrapText = False
For i = 1 To tmp.Rows.Length - 1
k = k + 1
For j = 0 To tmp.Rows(i).all.Length - 1
Cells(k, j + 1) = tmp.Rows(i).Cells(j).innertext
Next
Next
k = k + 1
Set tmp = .Document.getelementsbytagname("table")(82)<==== (82)又是何意??
For i = 0 To tmp.Rows.Length - 1
k = k + 1
For j = 0 To tmp.Rows(i).all.Length - 1
Cells(k, j + 1) = tmp.Rows(i).Cells(j).innertext
Next
因原網頁就在輸入 6121 就停住了,未能觸發網頁帶出資料,故後續的 table 就無法抓出數據帶入execl,請問先進需如何修改才好..TKS!!作者: Hsieh 時間: 2012-3-2 09:19
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate URL
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
For Each n In .Document.getelementsbytagname("INPUT") '這個迴圈找到按鈕是第幾個輸入項
kn = n.Value
If kn = "查詢" Then Exit For
s = s + 1
Next .Document.all("input_stock_code").Value = 6121 '要查的代碼
.Document.getelementsbytagname("INPUT")(s).Click '<=====巨集執行到此就錯誤,請問這一行是為何意,找了很久查不出是何意
Application.Wait Now + TimeValue("00:00:02") '等待2秒更新資料
Set tmp = .Document.getelementsbytagname("table")(79) '<==== (79)又是何意??79就表示第80個表格
此網頁擷取請測試