Antonio
Antonio

Reputation: 143

click on link text in internet explorer using vba

I want to Click on a link using VBA. The link is on a page and doesn't have a tag or id. The link only has a "link text". The link looks like this:

<a href="http://bulksell.ebay.de/ws/eBayISAPI.dll?FileExchangeDownload&amp;RefId=40637977">Herunterladen</a>

I made the following code in VBA, but I think that it doesn't work because the link doesn't have an ID or something.

Private Sub IE_orderdata_downloaden()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")

    'IE.Visible = False

    IE.Navigate "http://k2b-bulk.ebay.de/ws/eBayISAPI.dll?SMDownloadPickup&ssPageName=STRK:ME:LNLK"

    ' Wait while IE loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    IE.Visible = True

Set Link = IE.document.getElementsByTagName("a")
    For Each l In Link
        If Link.classname = "Herunterladen" Then
            Link.Click
            Exit For
        End If
    Next l

End Sub

Does someone have any idea how to make this work?

Best regards, and thank you all in advance!

Upvotes: 0

Views: 6016

Answers (1)

Domenic
Domenic

Reputation: 8104

Try using innerText instead of classname. Also, you should refer to your control variable l, not Link.

For Each l In Link
    If l.innerText = "Herunterladen" Then
        l.Click
        Exit For
    End If
Next l

Hope this helps!

Upvotes: 2

Related Questions