J P
asked on
Select Value from Webpage Dropdown using VBA
I wish to use vba to select a value from a webpage dropdown box.
The name of the dropdown box is "ad_award_name" so I need to use (presumably) GetelementsByName("ad_awar d_name").
I want to select from the dropdown box the value "Test1".
How would I do this please?
Thanks
Jim
The name of the dropdown box is "ad_award_name" so I need to use (presumably) GetelementsByName("ad_awar
<select name="ad_award_name" onchange="javascript:submitLink(document.Form0,'NotRequired');" displayname="Award Name">
</select>
I want to select from the dropdown box the value "Test1".
How would I do this please?
Thanks
Jim
ASKER
1:doc.GetelementsByName("a d_award_na me").value = "Test1" did not work.
I got the VBA error "Run-Time error '438', Object doesn't support this property or method".
Any ideas?
I got the VBA error "Run-Time error '438', Object doesn't support this property or method".
Any ideas?
then try
doc.GetelementsByName("ad_award_name")(0).value = "Test1"
doc.GetelementsByName("ad_award_name")(0).FireEvent("onchange")
ASKER
No error message on 1: or 2: BUT nothing has changed on webpage. That is "Test1" has not been selected.
Any idea?
Any idea?
Nope
ASKER
Thanks for trying Rgonzo, much appreciated.
ASKER
I am running IE11. I wonder if the issue is with the fireevent line because of IE11?
then try
Dim objEvent
doc.GetelementsByName("ad_award_name")(0).value = "Test1"
Set objEvent = doc.createEvent("HTMLEvents")
objEvent.initEvent "change", False, True
doc.GetelementsByName("ad_award_name")(0).dispatchEvent objEvent
ASKER
Ok the below works BUT I want to I want line 2: to = "Test1" rather than the selectindex. Any idea?
ie.document.getElementsByName("ad_award_name")(0).Focus
ie.document.getElementsByName("ad_award_name")(0).selectedIndex = 2
ie.document.getElementsByName("ad_amount_payable")(0).Focus
ie.document.getElementsByName("ad_award_name")(0).FireEvent ("onchange")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant! Thank you! Works perfectly!
How did you solve it?
How did you solve it?
So instead of giving the value I loop trough the values and select the one corresponding to your text
ASKER
Thanks Rgonzo! Have a good day!
pls try
Open in new window
Regards