• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 54
  • Last Modified:

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_award_name").

<select name="ad_award_name" onchange="javascript:submitLink(document.Form0,'NotRequired');" displayname="Award Name">
</select>

Open in new window


I want to select from the dropdown box the value "Test1".

How would I do this please?

Thanks

Jim
0
J P
Asked:
J P
  • 7
  • 6
1 Solution
 
Rgonzo1971Commented:
Hi,

pls try
doc.GetelementsByName("ad_award_name").value = "Test1"
doc.GetelementsByName("ad_award_name").FireEvent("onchange")

Open in new window

Regards
0
 
J PAuthor Commented:
1:doc.GetelementsByName("ad_award_name").value = "Test1" did not work.

I got the VBA error "Run-Time error '438', Object doesn't support this property or method".

Any ideas?
0
 
Rgonzo1971Commented:
then try
doc.GetelementsByName("ad_award_name")(0).value = "Test1" 
doc.GetelementsByName("ad_award_name")(0).FireEvent("onchange")

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
J PAuthor Commented:
No error message on 1: or 2: BUT nothing has changed on webpage. That is "Test1" has not been selected.

Any idea?
0
 
Rgonzo1971Commented:
Nope
0
 
J PAuthor Commented:
Thanks for trying Rgonzo, much appreciated.
0
 
J PAuthor Commented:
I am running IE11. I wonder if the issue is with the fireevent line because of IE11?
0
 
Rgonzo1971Commented:
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

Open in new window

0
 
J PAuthor Commented:
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")

Open in new window

0
 
Rgonzo1971Commented:
then try

set e = ie.document.getElementsByName("ad_award_name")(0)
    For Each o In e.Options
        If StrComp(o.Text, "Test1", vbTextCompare) = 0 Then
            o.Selected = True
            Exit For
        End If
    Next
e.FireEvent ("onchange")

Open in new window

0
 
J PAuthor Commented:
Brilliant! Thank you! Works perfectly!

How did you solve it?
0
 
Rgonzo1971Commented:
So instead of giving the value I loop trough the values and select the one corresponding to your text
1
 
J PAuthor Commented:
Thanks Rgonzo! Have a good day!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now