How do I click a link on a web page using Excel VBA?

Try getting the collection of anchor tags, with:

GetElementsByTagName("a")

Then, iterate that collection using as much logic as you can to ensure you’re clicking the right button.

For each l in ie.document.getElementsByTagName("a") 
    If l.ClassName = "hqt_button" Then
        l.Click
        Exit For
    Next

If there are multiple anchors with the same classname, you could do:

    If l.ClassName = "hqt_button" AND l.Href = ""https://stackoverflow.com/questions/24638533/javascript:void(0): onclick=HeaderBox.trySubmit()" Then
        l.Click
        Exit For
    Next

Alternatively

If you are using IE9+ you could use the GetElementsByClassName method.

GetElementsByClassName("hqt_button")   

Leave a Comment