red*_*lue 2 html excel internet-explorer vba excel-vba
给定一个url,如何在Excel中获取VBA中html页面的标题?
例如,假设我有三个网址:
现在我需要在另一列中获取这些html页面的标题.我该怎么做?
小智 6
Remou的回答对我非常有帮助,但它引起了一个问题:它没有关闭Internet Explorer进程,所以因为我需要运行这几十次我最终打开了太多的IE,而我的计算机无法处理这个.
所以只需添加
wb.Quit
Run Code Online (Sandbox Code Playgroud)
一切都会好的.
这是适合我的代码:
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
Run Code Online (Sandbox Code Playgroud)
我不确定你的标题是什么意思,但这是一个想法:
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
Run Code Online (Sandbox Code Playgroud)