• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

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

darius12

New Member
Hello, i am trying to click on a link that changes it's href value but it's classname it is always the same. What i do know about the link that i will click it is it's position, eg: the first link presented, or the third or another.
The code that i have now gives me a run time 438 on this line
Code:
If link.className = "KambiBC-event-item__link KambiBC-js-event-item-link" Then
.As if there is no link with this class?

Code:
Sub useClassnames()
    Dim row            As Long
    Dim link            As IHTMLElementCollection
    Dim ie              As InternetExplorer

    Set ie = New InternetExplorer

    With ie
        .navigate "https://www.unibet.ro/betting#filter/all/all/all/all/in-play"
        .Visible = True

        Do While ie.readyState <> READYSTATE_COMPLETE
            DoEvents
        Loop
    End With

    Do Until ie.document.getElementsByClassName("KambiBC-event-item__participants-container").Length > 0
        DoEvents
    Loop

    row = 1

    If Cells(row, 1).Value = 0 And Cells(row, 2).Value = 0 And Cells(row, 3) > 38 Then
        Set link = ie.document.getElementsByTagName("a")
        For Each l In link
            If link.className = "KambiBC-event-item__link KambiBC-js-event-item-link" Then
                link.Click
                Exit For
            End If
        Next
        row = row + 1
    End If
End Sub
 
Back
Top