Use VBA to activate JavaScript checkbox function in IE6?

E

Ed

I'm writing a VBA macro in Word 2003 that finds and manipulates a web
page (Win XP, IE6 sp2). I am having trouble with a checkbox. I can
find the checkbox and make it checked, but I can't figure out how to
activate the function connected to the OnClick event. Would anyone be
able to help me out here, please?

Thanks.
Ed
 
S

scripts.contact

Ed said:
I'm writing a VBA macro in Word 2003 that finds and manipulates a web
page (Win XP, IE6 sp2). I am having trouble with a checkbox. I can
find the checkbox and make it checked, but I can't figure out how to
activate the function connected to the OnClick event. Would anyone be
able to help me out here, please?


checkboxElement.onclick()
 
E

Ed

checkboxElement.onclick()

I tried
objCB.checkboxElement.onclick()
and
objCB.onclick()
and VBA kept giving me an error message that it expects an = after the
expression.
So I tried
objCB.onclick() = "selectAllCheckboxes"
which is the name of the function called by the onClick event, and
still nothing happened. (Checking this one box activates a function
which checks all boxes on the page.)

Here's what I've got so far:
Dim objCB
Set objCB = docIE.getElementById("selectAllCB")
objCB.Checked = True ' This does check the box, but only this box.
' None of these activate the function to select all the boxes.
objCB.onclick = "selectAllCheckboxes"
Call
docIE.parentWindow.execScript("javascript:selectAllCheckboxes",
"JavaScript")
objCB.onclick() = "selectAllCheckboxes"

If you could drop-kick me a bit further down the road on this, I would
be very grateful.

Ed
 
S

scripts.contact

I tried
objCB.checkboxElement.onclick()
and
objCB.onclick()
and VBA kept giving me an error message that it expects an = after the
expression.
So I tried
objCB.onclick() = "selectAllCheckboxes"
which is the name of the function called by the onClick event, and
still nothing happened. (Checking this one box activates a function
which checks all boxes on the page.)

Here's what I've got so far:
Dim objCB
Set objCB = docIE.getElementById("selectAllCB")
objCB.Checked = True ' This does check the box, but only this box.
' None of these activate the function to select all the boxes.
objCB.onclick = "selectAllCheckboxes"
Call
docIE.parentWindow.execScript("javascript:selectAllCheckboxes",
"JavaScript")
objCB.onclick() = "selectAllCheckboxes"

If you could drop-kick me a bit further down the road on this, I would
be very grateful.

Why dont you write your own VB function to check all checkboxes. try
this:
Set checks=document.getelementsbytagname("input")
for each check in checks
if check.type="checkbox" then check.checked=true
next


OR try this if you have to use the selectAllCheckboxes function:
docIE.parentWindow.location.href="javascript:selectAllCheckboxes()"

OR
docIE.parentWindow.execScript("javascript:selectAllCheckboxes()","JavaScript")

OR
Dim objCB
Set objCB = docIE.getElementById("selectAllCB")
objCB.Checked = True
objCB.onclick
 
E

Ed

OR
Dim objCB
Set objCB = docIE.getElementById("selectAllCB")
objCB.Checked = True
objCB.onclick

That was it! So simple that I couldn't see it. Thank you very much!

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top