views:

40

answers:

1

Hi, guys. This is a VBS script that opens google, fills a form, and clicks a search button.

set ie = CreateObject("InternetExplorer.Application")

ie.navigate("www.google.com")

ie.visible = true

while ie.readystate <> 4
    wscript.sleep 100
WEnd

set fields = ie.document.getelementsbyname("q")
set buttons = ie.document.getelementsbyname("btnG")

fields(0).value = "some query"
buttons(0).click

ie.quit

Sub OnClickSub()
    MsgBox  "button clicked!", 0
End Sub

Obviously, buttons(0).click fires an onclick event of the button, which I somehow need to catch in my script, and provide it with some processing like launching OnClickSub().

Has anyone got any ideas how this should be done?

+1  A: 

Use the GetRef function to obtain a pointer to your event handler and bind it to the onclick event, like this:

buttons(0).onclick = GetRef("OnClickSub")

(Apparently, attachEvent doesn't work when called from outside the web page.)

Helen
Thanks, that seems to work fine.
be here now