想要点击超链接(<a> tag) in IE through Excel VBA

时间:2017-08-01 23:44:29

标签: excel vba excel-vba

Want to click the hyperlink ( tag) 'abc' in IE through Excel VBA. Tried getElementbyTag/getElementsbyName/getElementsbyClassName but no luck so please help me on this

    <a href = 'xyz'> abc </a>


    Dim objIE As InternetExplorer
    set objIE = New InternetExplorer
    objIE.Visible = True
    objIE.Document.getElementsByTagName("xyz").Click

1 个答案:

答案 0 :(得分:2)

getElementsByTagName会返回一组链接,因此您需要循环查找所需的链接。

Dim l

For Each l in objIE.Document.getElementsByTagName("a")
    If l.innerText = "abc" Then
        l.Click
        Exit For
    End If
Next l