0

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>

7
  • can you provide the actual URL? or at least post the HTML code where the link is triggered? ... or look at this answer Commented Dec 7, 2015 at 16:23
  • Of the href or the original site? Commented Dec 7, 2015 at 16:24
  • URL of site where you want to click the link (javascript function) or the HTML code of that click (function) Commented Dec 7, 2015 at 16:26
  • just added it in description Commented Dec 7, 2015 at 16:26
  • 1
    I knew I had this same issue before .. see this question I asked a few months back and let me know if it solves the issue ... either of the answer(s) on the page ... maybe its not the same, but it seems similar... can you post the javascript function as well? Commented Dec 7, 2015 at 16:31

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.