返回列表 上一主題 發帖

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

回復 56# GBKEE


    請問 GBKEE  版主
   ie.Navigate "about:Tabs"
  作用是如何,謝謝

TOP

回復 61# wufonna [/b


   
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 60# GBKEE
(如果把 Set ie 以及 ie.Quit 改成註釋)
附上測試用程式碼:
  1. Sub 鉅享網2()
  2.     Dim URL As String, shts As Worksheet, ie As Object
  3.     Dim x As Variant, A As Object
  4.    
  5.     '  Set ie = CreateObject("InternetExplorer.Application")
  6.     '  ie.Navigate "about:Tabs"
  7.     '  ie.Visible = True
  8.    
  9.     Set shts = ActiveSheet    '  Sheets("工作表2")
  10.     shts.Cells.Clear
  11.    
  12.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  13.     With CreateObject("InternetExplorer.Application")
  14.         .Visible = True     '  是否顯示 IE
  15.         .Navigate URL
  16.         
  17.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  18.         
  19.         For Each x In .Document.getElementsBytagname("input")
  20.             If x.Value = "查詢" Then x.Click: Exit For
  21.         Next
  22.         
  23.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  24.         
  25.         Set A = .Document.getElementsBytagname("table")
  26.         For x = 1 To 6
  27.             '  With ie
  28.                 .Document.body.innerHTML = A(x).outerHTML
  29.                 .ExecWB 17, 2       '  Select All
  30.                 .ExecWB 12, 2       '  Copy selection
  31.             '  End With
  32.             
  33.             With shts
  34.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  35.                 .PasteSpecial Format:="HTML"
  36.             End With
  37.         Next
  38.         
  39.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  40.         .Quit
  41.     End With
  42.    
  43.     '  ie.Quit
  44. End Sub
複製代碼

TOP

回復 60# GBKEE
我原本的測試程式碼:
  1. Sub 鉅享網3()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer
  4.    
  5.     Set shts = ActiveSheet        '  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.         Do While .ReadyState <> 4 Or .Busy
  13.             DoEvents
  14.         Loop
  15.             
  16.         For Each x In .Document.getElementsBytagname("input")
  17.             If x.Value = "查詢" Then x.Click: Exit For
  18.         Next
  19.             
  20.         shts.Cells.Clear
  21.         For xi = 1 To 6
  22.             '  .document.body.innerHTML = .document.getElementsBytagname("table")(1).outerHTML
  23.             .Document.body.innerHTML = .Document.getElementsBytagname("table")(xi).outerHTML
  24.             .ExecWB 17, 2       '  Select All
  25.             .ExecWB 12, 2       '  Copy selection
  26.             
  27.             With shts
  28.                 '  .Cells.Clear
  29.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  30.                 .PasteSpecial Format:="HTML"
  31.                 '  .Cells.EntireColumn.AutoFit     '  自動調整欄寬
  32.             End With
  33.         Next xi
  34.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  35.         
  36.         .Quit
  37.     End With
  38. End Sub
複製代碼

TOP

本帖最後由 GBKEE 於 2013-11-22 07:16 編輯

回復 64# c_c_lai
在2003也是有這錯誤,經儲存內容再還原,就沒有這錯誤.
  1.     Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  2.         xlHtm = .Document.body.innerHTML                '儲存
  3.         Set A = .Document.getElementsBytagname("table")
  4.         For xi = 1 To 6
  5.             .Document.body.innerHTML = A(xi).outerHTML
  6.             .ExecWB 17, 2       '  Select All
  7.             .ExecWB 12, 2       '  Copy selection
  8.             With shts
  9.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  10.                 .PasteSpecial Format:="HTML"
  11.             End With
  12.             .Document.body.innerHTML = xlHtm                  '還原
  13.         Next xi
複製代碼
之後在為了不儲存再還原. 才有56#的程式碼在空白網頁放置 "table"的寫法
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 c_c_lai 於 2013-11-22 07:36 編輯

回復 60# GBKEE
(圖中 與54# 的程式碼有點不樣)
附上執行之程式碼:
  1. Sub 鉅享網4()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer, A As Object, xlHtm
  4.     Set shts = ActiveSheet '  '("工作表2")
  5.     shts.Cells.Clear
  6.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  7.     With CreateObject("InternetExplorer.Application")
  8.         .Visible = True     '  是否顯示 IE
  9.         .Navigate URL
  10.          Do While .ReadyState <> 4 Or .Busy
  11.                 DoEvents
  12.             Loop
  13.         For Each x In .Document.getElementsBytagname("input")
  14.             If x.Value = "查詢" Then x.Click: Exit For
  15.         Next
  16.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  17.         xlHtm = .Document.body.innerHTML                '儲存
  18.         Set A = .Document.getElementsBytagname("table")
  19.         For xi = 1 To 6
  20.             .Document.body.innerHTML = A(xi).outerHTML
  21.             .ExecWB 17, 2       '  Select All
  22.             .ExecWB 12, 2       '  Copy selection
  23.             With shts
  24.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  25.                 .PasteSpecial Format:="HTML"
  26.             End With
  27.             .Document.body.innerHTML = xlHtm                  '還原
  28.         Next xi
  29.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  30.         .Quit
  31.     End With
  32. End Sub
複製代碼

P.S.     這是剛才才執行出來的決果。

TOP

回復 65# GBKEE
(56#的程式碼在空白網頁放置 "table"的寫法)
我將 "空白網頁" 隱藏起來視覺上清爽多了。
  1.     Set ie = CreateObject("InternetExplorer.Application")
  2.     ie.Navigate "about:Tabs"
  3.     '  ie.Visible = True
複製代碼
執行決果一切 OK。

TOP

本帖最後由 GBKEE 於 2013-11-22 07:44 編輯

回復 67# c_c_lai
66# 說的錯誤,2003沒有發生.
2個ie都可以不顯示,那更清爽的.
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 68# GBKEE
說的也是!
謝謝指導。

TOP

回復 68# GBKEE
事後想想,發覺利用 "空白網頁" 來做為臨時戰場  (進行複製工作),
這個 Idea 蠻好的,亦不會破壞原本網頁的 Table 內容。
  1.         Set A = .Document.getElementsBytagname("table")
  2.         For x = 1 To 6
  3.             With ie
  4.                 .Document.body.innerHTML = A(x).outerHTML
  5.                 .ExecWB 17, 2       '  Select All
  6.                 .ExecWB 12, 2       '  Copy selection
  7.             End With
  8.             
  9.             With shts
  10.                 .Range("A" & .[A65535].End(xlUp).Row + 1).Select
  11.                 .PasteSpecial Format:="HTML"
  12.             End With
  13.         Next
複製代碼

TOP

        靜思自在 : 發脾氣是短暫的發瘋。
返回列表 上一主題