简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM