By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Use VBA to activate JavaScript checkbox function in IE6?

P: n/a
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

Jun 19 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Ed wrote:
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()

Jun 20 '07 #2

P: n/a
Ed
On Jun 19, 4:55 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Ed wrote:
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()
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:selectAl lCheckboxes",
"JavaScript")
objCB.onclick() = "selectAllCheckboxes"

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

Ed

Jun 20 '07 #3

P: n/a
On Jun 20, 7:43 am, Ed <prof_ofw...@yahoo.comwrote:
On Jun 19, 4:55 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Ed wrote:
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()

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:selectAl lCheckboxes",
"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:selec tAllCheckboxes()"

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

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

Jun 20 '07 #4

P: n/a
Ed
On Jun 20, 7:02 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On Jun 20, 7:43 am, Ed <prof_ofw...@yahoo.comwrote:
>>snip<<
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

Jun 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.