Hello,

I am trying to acquaint myself with VBA's getElementsByTagName, but I am struggling to make it work for me. I use Microsoft Office 2013, and have enabled Microsoft Internet Control and Microsoft HTML Object Library. In the following code, I am trying to grab the birthdate and place it in cell A1. However, this code seems to do nothing. It does not seem to even produce an error.

Sub Extract_TD_text()

Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long

'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
URL = [Wikipedia page for Rihanna (not allowed to paste HTML here)]

Set IE = New InternetExplorer

With IE
.navigate URL
.Visible = True

'Wait for page to load
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

Set HTMLdoc = .document
End With

Set TDelements = HTMLdoc.getElementsByTagName("TD")


r = 0
For Each TDelement In TDelements
'Look for required TD elements - this check is specific to VBA Express forum - modify as required
If TDelement.className = "infobox.vcard.plainlist" Then
Sheet1.Range("A1").Offset(r, 0).Value = TDelement.innerText
r = r + 1
End If
Next
IE.Quit

End Sub
Thanks for your time.