从访问VBA调用Javascript函数

时间:2015-12-07 16:20:41

标签: javascript vba access-vba ms-access-2010

在访问vba中

我能够从网站检索href标签,但是我发现href值触发了javascript函数而不是链接。 javascript函数将用户定向到我想要的链接。我的问题是:如何通过VBA触发javacript函数?

        Set ie1 = New InternetExplorer
        ie1.Navigate b.href 'Error here

        'wait for website to load
        Do: Loop While ie1.Busy Or ie1.ReadyState <> 4

        Set blist = HTML.getElementsByTagName("td")

        For Each c In blist

            address = c.innerText
            Debug.Print address

        Next c

编辑:b看起来像<a href="javascript:dspctry(71)">DNK</a>

1 个答案:

答案 0 :(得分:0)

解决了它,我使用IE.Document.parentWindow.excScript(b.href,“Javacript”)来调用javascript函数,同时将IE.Document设置为我当前的函数。

            'b.Click
            Call HTML.parentWindow.execScript(b.href, "Javascript")
            Do: Loop While ie.Busy Or ie.ReadyState <> 4

            Set blist = HTML.getElementsByTagName("td")

            For Each c In blist

                address = c.innerText
                If InStr(address, "Email: ") Then
                    Debug.Print address
                End If

            Next c

            Set HTML = Nothing
            Exit Function