Satheesh47
Satheesh47

Reputation: 31

How to click the hyperlink (<a> tag) in Internet Explorer through Excel VBA?

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

Answers (1)

Tim Williams
Tim Williams

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

Related Questions