Skip to content Skip to sidebar Skip to footer

Clicking On Hyperlink With Partial Href On Internet Explorer Using Vba

Hi I am trying to create a script to click on a link of which I can provide a partial link. It would be great if someone may please advise how I can do this EndWithEnd Sub

Besides, you could also find the tag use the getelementsbytagname method, then using for statement to loop through the result, and according to the innerText property to find the special link. Finally, click it.

Edit

You could check the following code:

Public Sub ClickTest()

    Dim ie AsObject    
    Dim itemlist AsObject'Define a object to store the a tag list.

    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate2 "<the website url>"

        While .Busy Or .readyState <> 4: DoEvents: Wend

        'ie.Document.querySelector("a[href^='website/report/download.json']").Click

        Set itemlist = ie.document.getElementsByTagName("a")

        'Debug.Print itemlist.Length  ' check the count of a tag

        If Len(itemlist) > 0 Then
            'using For Each statement to loopthough the a tag list.
            For Each Item In itemlist
                'Debug.Print Item.innerText  ' check the value
                'If the value is "GeneralExtract.xlsx", click the link andexit the for statement.
                If Item.innerText Like "GeneralExtract.xlsx" Then
                    Item.Click
                    ExitFor
                End If
            Next Item
        End If

    End With
End Sub

Post a Comment for "Clicking On Hyperlink With Partial Href On Internet Explorer Using Vba"