Consulting

Results 1 to 2 of 2

Thread: Unable to select a value in a DropDown List in a Webpage using VBA

  1. #1
    VBAX Regular
    Joined
    Jul 2015
    Posts
    8
    Location

    Unable to select a value in a DropDown List in a Webpage using VBA

    Hello all,

    I am trying to select a value in a dropdown list I have on an intranet webpage.

    The Html code of the dropdown list is as follows:

    <SELECT name="findby" tabIndex="1" class="selectCode" onchange="changeSearchBy();document.filteringForm.criterion.focus();return true;"  > 
    <OPTION selected value=Name>Name</OPTION>
    <OPTION value=RICOS>Ricos</OPTION>
    <OPTION value=SGC>SGC</OPTION> 
    <OPTION value=DIG>DIG</OPTION> 
    <OPTIONvalue=RMC>RMC</OPTION> 
    <OPTION value=REUTERS>REUTERS</OPTION> 
    </SELECT]>
    Now my code is as follows:
    Sub navigateGCE()
    Dim ie As New InternetExplorer
    Dim IEDoc As HTMLDocument
    Dim htmlSelectElem As Variant
    Dim elementHtml As Object
    
    ie.Visible = True
    '
    ie.navigate "MY INTRANET WEBPAGE"
        
    Do While ie.Busy Or Not ie.readyState = READYSTATE_COMPLETE
            DoEvents
    Loop
            
        
    Set IEDoc = ie.document
    
    
    Set htmlSelectElem = IEDoc.getElementsByTagName("findby")
    htmlSelectElem.selectedIndex = 2
    IEDoc.parentWindow.execScript "changeSearchBy()", "JavaScript"
      
     Set ie = Nothing
    Set IEDoc = Nothing
       
        
    End Sub
    It is to be noted that I have declared htmlSelectElem as Variant, using the debugger I see the type of this object is DispHTMLElementCollection.

    When I execute the code I have :
    Run time error 438, Object doesn't support this property or method
    I have tried to use getElementsByName instead but it doesn't work.

    Do you know how I can fix this?

    Many thanks

  2. #2
    VBAX Regular
    Joined
    Jul 2015
    Posts
    8
    Location
    I found the issue guys, it was because I had an other element called "finbdy" on my webpage.

    So I had to do it like this:
    Set iCollection = IEDoc.all("findby")
    Set generic = iCollection(1)
    generic.Value = "RICOS"
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •