- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
3#
發表於 2015-11-9 08:42
| 只看該作者
回復 1# hsueh0926
試試看- Option Explicit
- Sub Ex() '方法一 純文字
- Dim Sh As Worksheet, i As Integer, k As Integer, R As Variant
- With CreateObject("InternetExplorer.Application")
- .Visible = True
- .Navigate "http://norway.twsthr.info/StockHolders.aspx?stock=2454"
- '資料在 .Document.all.Tags("table")(9)
- Set Sh = ActiveSheet
- Sh.UsedRange.Clear
- Application.StatusBar = "等候網頁中..."
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Application.StatusBar = "網頁下載完畢...."
- Application.ScreenUpdating = False
- For Each R In .Document.all.Tags("table")(9).Rows
- k = k + 1
- For i = 0 To R.Cells.Length - 1
- Sh.Cells(k, i + 1) = R.Cells(i).innerText
- Next
- Next
- Sh.UsedRange.SpecialCells(xlCellTypeBlanks).Delete
- Application.ScreenUpdating = True
- .Quit
- End With
- End Sub
複製代碼- Sub Ex2() '方法二 網頁格式
- With CreateObject("InternetExplorer.Application")
- ' .Visible = True
- .Navigate "http://norway.twsthr.info/StockHolders.aspx?stock=2454"
- Application.StatusBar = "等候網頁中..."
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Application.ScreenUpdating = False
- Ep .Document.all.Tags("table")(9).outerHTML
- Application.StatusBar = "網頁下載完畢...."
- Application.ScreenUpdating = True
- .Quit
- End With
- End Sub
- Sub Ep(S As String)
- Dim Sh As Worksheet
- With CreateObject("InternetExplorer.Application")
- .Navigate "about:Tabs"
- ' .Visible = True
- .Document.body.innerHTML = S
- .ExecWB 17, 2 ' Select All
- .ExecWB 12, 2 ' Copy selection
- Set Sh = ActiveSheet
- With Sh
- .Range("A1").Select
- .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=False
- End With
- .Quit
- End With
- End Sub
複製代碼 |
|