2013-08-22 84 views
2

所以我正在尋找將一堆網址從網頁轉儲到excel中作爲列表。我以前曾將這些項目轉儲到列表框中,但我發現列表框非常難以使用!從網頁上刮掉的粘貼網址

一旦我將這些URL收集到excel中的列中,我希望excel單擊每個鏈接並查找頁面上的電子郵件地址。這裏是我目前的編碼...

Dim IE As Object 
Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 

url_name = Sheet1.Range("A2") 
If url_name = "" Then Exit Sub 

IE.Navigate (url_name) 

Do 
DoEvents 
Loop Until IE.ReadyState = 4 

Set AllHyperLinks = IE.Document.GetElementsByTagName("A") 

For Each hyper_link In AllHyperLinks 

Range("x":"F").Value = hyper_link 

這是我迄今爲止所有的!我不知道如何完成循環!我想要的代碼粘貼它找到頁面上的下一個空行中列F.

每一個新的URL

回答

0

可以完成這樣的循環:

Dim IE As Object, LR As Long, i As Long 
LR = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row 
Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
For i = 2 To LR 
url_name = Sheet1.Range("A" & i).Value 
If url_name = "" Then Exit Sub 

IE.Navigate (url_name) 

Do 
DoEvents 
Loop Until IE.ReadyState = 4 

Set AllHyperLinks = IE.Document.GetElementsByTagName("A") 

For Each hyper_link In AllHyperLinks 

Range("x":"F").Value = hyper_link 

Next hyper_link 
Next i 

請注意,如果您有大量的數據,這將需要一個LOOOONGGGG時間。