首页 > 解决方案 > 单击锚链接 Excel VBA

问题描述

伙计们,我在使用 VBA 代码点击网站锚点时遇到了麻烦。

我要点击的链接如下:

<a href="http://www.hapvida.com.br/pls/webhap/webNewTrocaArquivo.Download?pPessoa=36561410&amp;pNoCache=1817001839&amp;pIdSessao=001718093818134569635">BAIXAR ARQUIVOS - DOWNLOAD</a>

我尝试了一些方法,但它们只适用于网站上的其他链接,但不适用于这个。

这就是我的代码现在的样子:

Sub login()

    Const Url$ = "https://www.hapvida.com.br/pls/webhap/webNewTrocaArquivo.login"

    Dim UserName As String, Password As String, LoginData As Worksheet
    Set LoginData = ThisWorkbook.Worksheets("1")

    UserName = LoginData.Cells(2, "B").Value
    Password = LoginData.Cells(3, "B").Value

    Dim ie As InternetExplorer

    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .Navigate Url
        ieBusy ie
        .Visible = True

        Dim oLogin As Object, oPassword As Object, oCodigo As Object

        Set oLogin = .Document.getElementsByName("pCpf")(0)
        Set oPassword = .Document.getElementsByName("pSenha")(0)

        oLogin.Value = UserName
        oPassword.Value = Password
        .Document.forms(0).submit

    End With

    For Each l In ie.Document.getElementsByClassName("ultimas_noticias")
        If l.tagName = "a" Then
            l.Click
        End If
    Exit For
    Next

End Sub

Sub ieBusy(ie As Object)
    Do While ie.Busy Or ie.ReadyState < 4
        DoEvents
    Loop
End Sub

非常感谢提前

标签: htmlexcelvbaanchor

解决方案


推荐阅读