2011年8月14日 星期日

Excel VBA 從網頁上抓資料匯入到 Excel中

'定義webURL字串變數
Dim webURL As String
'webURL為要匯入的網址
webURL = "URL;http://xxx.xxx.xxx.xxx/123.htm"
With ActiveSheet.QueryTables.Add(Connection:=webURL, Destination:=Range("A1"))
' xlOverwriteCells 表示覆蓋欄位
        .RefreshStyle = xlOverwriteCells
' 抓取網頁的第三個表格作為匯入資料
        .WebTables = "3"
        .Refresh BackgroundQuery:=False
End With

沒有留言: