Calling Javascript function from access VBA

喜欢而已 提交于 2020-01-06 19:56:31

问题


in access vba I'm able to retrieve an href tag from a website, however I found out that the href value triggers a javascript function rather than a link. The javascript function directs the user to a link that I want. My question is: how do I trigger that javacript function via VBA?

        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

EDIT: b looks like this <a href="javascript:dspctry(71)">DNK</a>


回答1:


Solved it, I used IE.Document.parentWindow.excScript(b.href,"Javacript") to call the javascript function while set its IE.Document to my current one.

            '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


来源:https://stackoverflow.com/questions/34138269/calling-javascript-function-from-access-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!