Hi all I have a web form to fill from a cell value from excel i cant use select by index. The scenario is in a webform dropdown there are dynamic names and I have a excel cell value containing names and it should read from cell value and update in form.
Please help me to modify this code
objIE.document.getElementById("ctl00_MainContent_userDDList").selectedIndex = 4
IE Automation to select dropdown based on cell value
- harsha6989
- Thread is marked as Resolved.
-
-
-
Try this, which searches the select dropdown for the required visible text and, if found, sets the select element's value property.
The code requires a reference to MS HTML Object Library - set via Tools - References in VBA.
Code
Display MoreDim selectElement As HTMLSelectElement Dim optionValue As String Set selectElement = objIE.document.getElementById("ctl00_MainContent_userDDList") optionValue = FindSelectOptionValue(selectElement, "The required visible text") 'Change this string as required If optionValue <> "" Then selectElement.Value = optionValue Else Msgbox "Option text not found" End If Private Function FindSelectOptionValue(selectElement As HTMLSelectElement, findOptionText As String) As String Dim i As Long FindSelectOptionValue = "" i = 0 While i < selectElement.Options.Length And FindSelectOptionValue = "" 'Debug.Print i, selectElement.Item(i).Value & " <" & selectElement.Item(i).Text & ">" If StrComp(selectElement.Item(i).Text, findOptionText, vbTextCompare) = 0 Then FindSelectOptionValue = selectElement.Item(i).Value i = i + 1 Wend End Function
-
Thank you so much for the help..Its working exactly the way I was looking for.Thanks a ton.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!