返回列表 上一主題 發帖

有關EXCEL VBA 抓取不到完整網址CSV問題

若是我想copy下列網址某天、某幾家的資料,http://stocker.com.tw/
可否請大大撥冗幫忙,有附檔
jak 發表於 2014/3/6 11:38

抱歉,沒有注意到,久等了.
試試看
  1. <input type="text" name="StoNum" id="StoNum" style="width:100px" value="1101" onkeyup="findStoNum()">
  2. '<input type="text" name="datestart" id="datepicker" style="width:80px" value="2014-05-09" class="hasDatepicker">
  3. '<input type="submit" class="senddata" value="提交">
  4. Option Explicit
  5. Dim FormDLL As String, xDate As Date, Sh As Worksheet ', Msg As Boolean
  6. Sub Ie_Table()
  7.     Dim URL As String, A As Object, i As Integer, E As Range
  8.     Set_FormDLL
  9.     URL = "http://stocker.com.tw/"
  10.     xDate = Date - 1
  11.     If Weekday(xDate, vbMonday) > 5 Then
  12.         Do While Weekday(xDate, vbMonday) > 5
  13.         xDate = xDate - 1
  14.         Loop
  15.     End If
  16.     Set Sh = Sheets.Add                   '結果顯示在新增的工作表
  17.     Sh.Name = Format(xDate, "yyyy-mm-dd") '命名為日期
  18.     With CreateObject("InternetExplorer.Application")
  19.         .navigate URL
  20.         .Visible = True
  21.         For Each E In Sheets("下載代號名單").Range("A3", Sheets("下載代號名單").[A3].End(xlDown))
  22.             Do While .Busy Or .ReadyState <> 4:         Loop
  23.             With .document.getElementsByTagName("input")
  24.                 .Item("StoNum").Value = E
  25.                 .Item("datestart").Value = Format(xDate, "yyyy-mm-dd")
  26.                 For i = 0 To .Length - 1
  27.                     If .Item(i).Type = "submit" Then .Item(i).Click
  28.                 Next
  29.             End With
  30.         Do While .Busy Or .ReadyState <> 4:         Loop
  31.         Set A = .document.getElementsByTagName("TABLE")
  32.         Ep A(A.Length - 1).outerHTML
  33.         Next
  34.         .Quit
  35.     End With
  36.     Remove_FormDLL
  37. End Sub
  38. Sub Ep(S As String)
  39.     Dim D As New DataObject, E As Shape
  40.     'DataObject 物件 在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  41.     '宣告 Dim D As New DataObject '須在工具-> 設定引用項目加入 新增引用 Microsoft Forms 2.0 Object Library ,專案 加入一表單即可
  42.     With D
  43.         .SetText S
  44.         .PutInClipboard
  45.         With Sh.UsedRange
  46.             If .Rows.Count = 1 Then
  47.                 .Cells(1).Select
  48.             Else
  49.                 .Rows(.Rows.Count).Cells(2).Select
  50.             End If
  51.             Sh.PasteSpecial Format:="Unicode 文字"
  52.              With ActiveCell
  53.                 .Cells(2, 1) = "日期"
  54.                 .Cells(3, 1).Resize(.Parent.UsedRange.Rows.Count - .Cells(3, 1).Row) = Format(xDate, "mm/dd")
  55.             End With
  56.             
  57.         End With
  58.     End With
  59. End Sub
  60. Sub Set_FormDLL()   '新增引用 Microsoft Forms 2.0 Object Library
  61.     On Error Resume Next
  62.     FormDLL = "FM20.DLL"
  63.     ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\FM20.DLL"
  64.     '"C:\windows\system32\"是2003版的路徑,2003以上版本需修改路徑
  65. End Sub
  66. Sub Remove_FormDLL() '刪除引用 Microsoft Forms 2.0 Object Library
  67.     Dim D As Object
  68.     For Each D In ThisWorkbook.VBProject.References
  69.         If UCase(D.fullpath) Like "*" & FormDLL Then
  70.             ThisWorkbook.VBProject.References.Remove D
  71.         End If
  72.     Next
  73. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2014-5-25 16:31 編輯

回復 45# jak
  1. Sub Ie_Table()
  2. Ep A(A.Length - 1).outerHTML, E '修改一下
  3. End Sub
複製代碼
  1. Sub Ep(S As String, Code As Range)
  2.     Dim D As New DataObject ', E As Shape
  3.     'DataObject 物件 在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  4.     '宣告 Dim D As New DataObject '須在工具-> 設定引用項目加入 新增引用 Microsoft Forms 2.0 Object Library ,專案 加入一表單即可
  5.     With D
  6.         .SetText S
  7.         .PutInClipboard
  8.         With Sh.UsedRange
  9.             If .Rows.Count = 1 Then
  10.                 .Cells(1).Select
  11.             Else
  12.                 .Rows(.Rows.Count).Cells(2).Select
  13.             End If
  14.             Sh.PasteSpecial Format:="Unicode 文字"
  15.              With ActiveCell
  16.                 .Cells(2, 1) = "代號"
  17.                 .Cells(3, 1).Resize(.Parent.UsedRange.Rows.Count - .Cells(3, 1).Row) = Code
  18.             End With
  19.             
  20.         End With
  21.     End With
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 47# jak
不好意思,最近常犯錯.46#的程式碼已更新
  1. Sub Ep(S As String, Code As Range)
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 人生不一定球球是好球,但是有歷練的強打者,隨時都可以揮棒。
返回列表 上一主題