返回列表 上一主題 發帖

EXCEL VBA 匯入goodinfo網頁資料

回復 2# chickout2

試試看
  1. Option Explicit
  2. Sub EX()
  3.     Dim i As Integer, E As Object, C As Integer, Sh As Worksheet
  4.     With CreateObject("InternetExplorer.Application")
  5.         .Visible = True
  6.         .Navigate "http://www.goodinfo.tw/stockinfo/ShowK_ChartFlow.asp?RPT_CAT=DR_3M&STOCK_ID=2454&CHT_CAT=MONTH"
  7.         Do While .Busy Or .readyState <> 4: DoEvents:      Loop
  8.         With .DOCUMENT
  9.             Do
  10.                 If .all.tags("table").Length >= 16 Then Exit Do
  11.                 DoEvents
  12.             Loop
  13.             Set Sh = ActiveSheet
  14.             Sh.UsedRange.Clear
  15.             For Each E In .all.tags("table")(16).Rows
  16.                 i = i + 1 '
  17.                 For C = 0 To E.Cells.Length - 1
  18.                     Sh.Cells(i, C + 1) = E.Cells(C).innertext
  19.                 Next
  20.             Next
  21.             With Sh
  22.                  For i = 21 To .Range("A" & Rows.Count).End(xlUp).Row Step 18
  23.                     .Cells(i, "A").Resize(2).EntireRow.Delete
  24.                 Next
  25.             End With
  26.         End With
  27.         .Quit        '關閉網頁
  28.     End With
  29. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

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