2011-10-02 84 views

回答

5

我不知道你所說的標題的意思,但在這裏是一個想法:

Dim wb As Object 
Dim doc As Object 
Dim sURL As String 

Set wb = CreateObject("InternetExplorer.Application") 

sURL = "http://lessthandot.com" 

wb.Navigate sURL 

While wb.Busy 
    DoEvents 
Wend 

''HTML Document 
Set doc = wb.document 

''Title 
Debug.Print doc.Title 

Set wb = Nothing 
+0

作品題目,我說的是HTML頁面的標籤中的內容。我會嘗試你的代碼。 – redGREENblue

+0

@redGREENblue這就是你將從上面得到的。 – Fionnuala

6

Remou的回答對我來說非常有幫助,但它造成一個問題:它不會關閉Internet Explorer進程,因爲我需要運行幾十次,所以我打開了太多的IE,而我的電腦無法處理這個問題。

所以只需添加

wb.Quit 

,一切都會好起來的。

這是對我的作品的代碼:

Function GetTitleFromURL(sURL As String) 
Dim wb As Object 
Dim doc As Object 

Set wb = CreateObject("InternetExplorer.Application") 

wb.Navigate sURL 

While wb.Busy 
    DoEvents 
Wend 

GetTitleFromURL = wb.Document.Title 

wb.Quit 

Set wb = Nothing 
End Function