问题
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