2

Given an url, how can I get the title of the html page in VBA in Excel?

For example suppose I have three urls like :

Now I need to get the title of these html pages in another column. How do I do it?

3 Answers 3

7

Remou's answer was VERY helpful for me, but it caused a problem: It doesn't close the Internet Explorer process, so since I needed to run this dozens of times I ended up with too many IEs open, and my computer couldn't handle this.

So just add

wb.Quit

and everything will be fine.

This is the code that works for me:

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
Sign up to request clarification or add additional context in comments.

Comments

5

I am not sure what you mean by title, but here is an idea:

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

2 Comments

By title, I meant the content within the <title></title> tag of the html page. I will try your code out.
@redGREENblue that is what you will get from the above.
0

if you use Selenium :

Sub Get_Title()
Dim driver As New WebDriver
debug.print driver.Title
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.