VBA: Select value from html dropdown

42Nice

New Member
Joined
Jun 18, 2018
Messages
8
Hi,

I come across a very challenging task that I can't find a way to accomplish.
The goal is to to fill/ choose value from a drop down list which I suspect has a Java script applied on it which not allowing me to easy choose value by id.
I manage to type in the value in the search bar, mimc mouse click on the dropdown list icon - see that the entered value is valid and exist in the list but I am not able to find a way how to choose the entered value!

As a human it action it would only be possible to choose the value by one of 2 ways: save = changes saved.
1) type in the value in the search bar, click on the icon to open the dropdown menu - if value is correct I will see the option and will be able to click on it ( the only way to choose is, and make the system save the changes)
2) Click on the drop down Icon > see few global options > open any of them (children) untill I find the desired value > left click on it > save = changes saved.

*Note: If I type the value and press enter it still wont be selected in the system. Only if I click on the value from the drop down menu only then the system will apply the changes after saving.


Code:
Sub User_Setup()
'Application.ScreenUpdating = False
'Application.DisplayAlerts = False
'----------------------------------here I define elemnts for the loop
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Fields")
Dim LastRow As Long
Dim i As Long
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
Dim values() As String
Dim b As Long
Dim frm As Object
Dim dt As Object
'---------------------------------------------here I define Internet Explorer
Dim IE As Object
Dim Doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
'--------------------------------------------- here I define range for the loop
For i = 2 To LastRow
' ---------------------------------------------here I ask the Internet explorer to be visable & Navigate to value in cell "H"i
IE.Visible = True
IE.navigate sht.Range("A" & i).Value

' ---------------------------------------------here I ask the Internet explorer to wait few seconds
Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
Loop
Set Doc = IE.document
'--------------------------------- Here is my issue with the dropdown
Doc.getElementById("tab7").Click ' clicks the tab where the dropdown exists
Doc.getElementById("ResourceWorkgroup").Value = sht.Range("X" & i).Value ' This is the value needs be choosen in the dropdown
Doc.getElementById("ResourceWorkgroup").FireEvent "onfocus" ' this event should make the value just inserted be highlited
'---- 
Doc.getElementById("_IB_imgResourceWorkgroup").Click ' this is the action that mimic mouse click on the "open drop down" icon
  Doc.getElementById("_IB_imgResourceWorkgroup").FireEvent "onfocus" 'not sure if this line is  even helpful
'----
[COLOR=#008000]'NOTE:I manage to enter the value in the search field, and the click the dropdown list icon,
'(mimic the mouse click on the open dropdown list icon) [/COLOR][COLOR=#ff0000]without really choosing the value.
[/COLOR]
 Application.Wait Now + TimeValue("00:00:10")
 Doc.getElementById("Master_IdBtnSave").Click ' click on save button
 Doc.getElementById("Master_IdBtnSave").FireEvent "*******" 'trigger the event of saving (not sure if this neccery aswell)

Next i

End Sub

Hope to find a hint from some one.
Thanks alot for your attention,
Nice42
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
HI,

So far tried many different ways but still no luck. I believe it has something to do with reffering to the right Item which I find hard to pull. Any ideas?
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,664
Members
449,247
Latest member
wingedshoes

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