2016-02-03 26 views
0

我正在拉我的頭髮。我已經看到幾乎可以解決這個問題的其他主題,但是他們的方法通常太具體。我不需要任何複雜的東西,只需要抓取Excel VBA腳本從URL的預定義列表中複製和粘貼數據

我的文件A列中有大約64,000個URL。我希望Excel能夠訪問每個URL,一旦它加載完畢,將整個頁面複製並粘貼到Excel中。我希望將所有粘貼的數據粘貼在同一個工作簿和同一張表中。

+0

請在閱讀本文之前詢問更多問題:http://stackoverflow.com/help/how-to-ask。我們不會爲您編寫代碼。您需要向我們展示您嘗試過的內容,告訴我們*特定*不起作用,我們可能會幫助您。 –

+0

*我不需要像刮臉那樣複雜* - 你真的明白刮刮是什麼以及它是如何工作的嗎?你正在問這個。但是,有一個可能會有所幫助的替代方案。請參閱Excel功能區中的「Data> From Web」。如果您不知道代碼,請使用宏記錄器開始使用代碼。 –

回答

0

那麼這裏是完成的代碼,如果有人想知道。

Sub Macro3() 
' 
' Macro3 Macro 
' 
' 
Dim Erw, Frw, Lrw 
Drw = 1 
Frw = 1 
Lrw = Range("A" & Rows.Count).End(xlUp).Row 
For Erw = Frw To Lrw 

With ActiveSheet.QueryTables.Add(Connection:= _ 
     "URL;" & Range("A" & Erw).Value, Destination:=Range("G" & Drw)) 
     .Name = "" 
     .FieldNames = True 
     .RowNumbers = False 
     .FillAdjacentFormulas = False 
     .PreserveFormatting = True 
     .RefreshOnFileOpen = False 
     .BackgroundQuery = True 
     .RefreshStyle = xlInsertDeleteCells 
     .SavePassword = False 
     .SaveData = True 
     .AdjustColumnWidth = True 
     .RefreshPeriod = 0 
     .WebSelectionType = xlSpecifiedTables 
     .WebFormatting = xlWebFormattingNone 
     .WebTables = "6" 
     .WebPreFormattedTextToColumns = True 
     .WebConsecutiveDelimitersAsOne = True 
     .WebSingleBlockTextImport = False 
     .WebDisableDateRecognition = False 
     .WebDisableRedirections = False 
     .Refresh BackgroundQuery:=False 
    End With 
    Drw = Drw + 80 
Next Erw 

End Sub