Reputation: 31
I want to click the hyperlink (<a>
tag) 'abc' in Internet Explorer through Excel VBA.
I tried getElementbyTag/getElementsbyName/getElementsbyClassName.
<a href = 'xyz'> abc </a>
Dim objIE As InternetExplorer
set objIE = New InternetExplorer
objIE.Visible = True
objIE.Document.getElementsByTagName("xyz").Click
Upvotes: 0
Views: 1139
Reputation: 166126
getElementsByTagName
returns a collection of links, so you need to loop over and find the one you want.
Dim l
For Each l in objIE.Document.getElementsByTagName("a")
If l.innerText = "abc" Then
l.Click
Exit For
End If
Next l
Upvotes: 3