Select the drop down option

VICKY2007

New Member
Joined
Mar 12, 2019
Messages
1
Sub mar()


Dim IE As New SHDocVw.InternetExplorer

IE.Visible = True
IE.navigate "http://aicf.in/national-tournament-registration/"

Do While IE.readyState <> 4
Loop

IE.document.getElementById ("national_plr_payments_form")



End Sub


Help me to select the drop down option
I don't know whether I have selected the correct element id.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Re: Help me to select the drop down option

Try this macro. You must set a reference (via Tools -> References in the VBA editor) to MS HTML Object Library.
Code:
Public Sub IE_Dropdown()

    Dim URL As String
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim dropdown As HTMLSelectElement
    Dim dropdownText As String, dropdownIndex As Long
    
    URL = "http://aicf.in/national-tournament-registration/"
    
    Set IE = New InternetExplorer
    With IE
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
        
    Set dropdown = HTMLdoc.getElementsByTagName("SELECT")(0)
    dropdownText = "*National RAPID*"
    dropdownIndex = FindSelectOptionIndex(dropdown, dropdownText)
    dropdown.Focus
    dropdown.Click
    dropdown.selectedIndex = dropdownIndex
    dropdown.FireEvent "onchange"

End Sub


Private Function FindSelectOptionIndex(selectElement As HTMLSelectElement, findOptionText As String) As Long

    Dim i As Long
    
    FindSelectOptionIndex = -1
    i = 0
    While i < selectElement.Options.Length And FindSelectOptionIndex = -1
        'Debug.Print i; selectElement.Item(i).Value & " >" & selectElement.Item(i).Text & "<"
        If LCase(selectElement.Item(i).Text) Like LCase(findOptionText) Then FindSelectOptionIndex = i
        i = i + 1
    Wend

End Function
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top