返回列表 上一主題 發帖

請問這個網頁如何用WEB查詢輸入excel

回復 47# ML089
以上圖解瞭解否?

TOP

回復 45# joey0415
參考:
  1. Sub 鉅享網()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer
  4.    
  5.     Set shts = Sheets("工作表2")
  6.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  7.    
  8.     With CreateObject("InternetExplorer.Application")
  9.         .Visible = True     '  是否顯示 IE
  10.         .Navigate URL
  11.         
  12.         shts.Cells.Clear
  13.         For xi = 1 To 6
  14.             Do While .readyState <> 4 Or .Busy
  15.                 DoEvents
  16.             Loop
  17.             
  18.             For Each x In .document.getElementsBytagname("input")
  19.                 If x.Value = "查詢" Then x.Click: Exit For
  20.             Next
  21.             
  22.             .document.body.innerHTML = .document.getElementsBytagname("table")(xi).outerHTML
  23.             .execwb 17, 2       '  Select All
  24.             .execwb 12, 2       '  Copy selection
  25.             
  26.             With shts
  27.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  28.                 .PasteSpecial Format:="HTML"
  29.             End With
  30.         Next xi
  31.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  32.         
  33.         .Quit
  34.     End With
  35. End Sub
複製代碼

TOP

回復 51# c_c_lai

點進去才之別有洞天

感謝! 圖解說明作的真用心
{...} 表示需要用 CTRL+SHIFT+ENTER 三鍵輸入公式

TOP

回復 45# joey0415
  1. Busy = True            
  2. Busy = False

  3. READYSTATE_UNINITIALIZED = 0
  4. READYSTATE_LOADING = 1
  5. READYSTATE_LOADED = 2
  6. READYSTATE_INTERACTIVE = 3
  7. READYSTATE_COMPLETE = 4
複製代碼
不想再CREAT另一個IE : 52# c_c_lai 已寫出了
回復 52# c_c_lai
在2003有錯誤修正如下
  1. Option Explicit
  2. Sub 鉅享網()
  3.     Dim URL As String, shts As Worksheet
  4.     Dim x As Variant, xi As Integer, A As Object, xlHtm
  5.     Set shts = ActiveSheet '  '("工作表2")
  6.     shts.Cells.Clear
  7.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  8.     With CreateObject("InternetExplorer.Application")
  9.         .Visible = True     '  是否顯示 IE
  10.         .Navigate URL
  11.          Do While .ReadyState <> 4 Or .Busy
  12.                 DoEvents
  13.             Loop
  14.         For Each x In .Document.getElementsBytagname("input")
  15.             If x.Value = "查詢" Then x.Click: Exit For
  16.         Next
  17.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  18.         xlHtm = .Document.body.innerHTML                '儲存
  19.         Set A = .Document.getElementsBytagname("table")
  20.         For xi = 1 To 6
  21.             .Document.body.innerHTML = A(xi).outerHTML
  22.             .ExecWB 17, 2       '  Select All
  23.             .ExecWB 12, 2       '  Copy selection
  24.             With shts
  25.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  26.                 .PasteSpecial Format:="HTML"
  27.             End With
  28.             .Document.body.innerHTML = xlHtm                  '還原
  29.         Next xi
  30.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  31.         .Quit
  32.     End With
  33. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 54# GBKEE
原本我亦是如您所寫的 (For ~ Next) 方式處哩,但它在 2010 版大約在第二迴圈便會出現
錯誤訊息,所以只能將 For 往上擺放,每次都再執行 Click 的動作,一切便順心了。
看樣子就像統計圖表繪製有些語法處理之適用問題一樣,只能依版本見機行事,
謝謝您!

TOP

回復 55# c_c_lai
我 54# 修正的程式碼2010不可用?
2010請試試看這程式碼
  1. Option Explicit
  2. Sub 鉅享網()
  3.     Dim URL As String, shts As Worksheet, ie As Object
  4.     Dim x As Variant, A As Object
  5.     Set ie = CreateObject("InternetExplorer.Application")
  6.     ie.Navigate "about:Tabs"
  7.     ie.Visible = True
  8.     Set shts = ActiveSheet '  '("工作表2")
  9.     shts.Cells.Clear
  10.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  11.     With CreateObject("InternetExplorer.Application")
  12.         .Visible = True     '  是否顯示 IE
  13.         .Navigate URL
  14.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  15.         For Each x In .Document.getElementsBytagname("input")
  16.             If x.Value = "查詢" Then x.Click: Exit For
  17.         Next
  18.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  19.         Set A = .Document.getElementsBytagname("table")
  20.         For x = 1 To 6
  21.             With ie
  22.             .Document.body.innerHTML = A(x).outerHTML
  23.             .ExecWB 17, 2       '  Select All
  24.             .ExecWB 12, 2       '  Copy selection
  25.             End With
  26.             With shts
  27.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  28.                 .PasteSpecial Format:="HTML"
  29.             End With
  30.         Next
  31.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  32.         .Quit
  33.     End With
  34.     ie.Quit
  35. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 56# GBKEE
只有一句話能形容    ----    Perfect!

TOP

回復 56# GBKEE
如果把 Set ie 以及 ie.Quit 改成註釋,則會發生如圖之錯誤:

TOP

回復 56# GBKEE
附上 54# 的程式執行結果:

TOP

回復 58# c_c_lai
如果把 Set ie 以及 ie.Quit 改成註釋,則會發生如圖之錯誤: 錯誤行是哪一行?
註釋後ie變數就沒有指定物件,再使用到ie當然會錯誤.
回復 59# c_c_lai
圖中 與54# 的程式碼有點不樣,明天再看看
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 願要大、志要堅、氣要柔、心要細。
返回列表 上一主題