Excel VBA 抓HTML 中的某一個Table
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# BarryHuang621a
你提供智慧選股工具的網址,在我的 XP, IE8 環境下執行很慢,有時會掛掉
請試試別的網址- Option Explicit
- Sub Ex()
- Dim D As Object, i As Integer, URL As String
- URL = "http://forum.twbts.com/thread-12273-1-2.html"
- 'URL = "http://www.goodinfo.tw/stockinfo/StockSorter.asp?"
- With CreateObject("InternetExplorer.Application")
- .Navigate URL
- .Visible = True
- Do While .ReadyState <> 4 Or .Busy
- DoEvents
- Loop
-
- Set D = .document.getElementsByTagName("table")
- ActiveSheet.Cells.Clear
- For i = 0 To D.Length - 1
- Ep i, D(i).outerHTML
- Next
- .Quit
- End With
- End Sub
- Private Sub Ep(i As Integer, S As String)
- Dim R
- With CreateObject("InternetExplorer.Application")
- .Navigate "about:Tabs"
- .Visible = True
- .document.body.innerhtml = S
- .ExecWB 17, 2 ' Select All
- .ExecWB 12, 2 ' Copy selection
- With ActiveSheet
- R = IIf(.UsedRange.Rows.Count = 1, 1, .UsedRange.Rows.Count + 2)
- .Cells(R, 1) = "第 " & i & " 個 Table"
- .Cells(R, 1).EntireRow.Interior.Color = vbYellow
- .UsedRange.Cells(R + 1, 1).Select
- .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
- End With
- .Quit
- End With
- End Sub
複製代碼 |
|
|
|
|
|
|
|