How to select drop down from a webpage using VBA code.

Rabi05

New Member
Joined
Jun 28, 2018
Messages
1
I am trying to pull up some data from a webpage, which will help me to generate my report faster.


In order to pull up those data, I have to choose a drop down. I have tried to select the drop down but it's not working.


Could you please check the below code and suggest where I am dong wrong.


Sub getoptdt()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "website name"


Do While ie.busy = True
DoEvents
Loop
Set html = ie.document


Dim drp As HTMLFormElement
Set drp = html.getElementById("<wbr>c12ssdrdq")


drp.selectedIndex = 2
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You might need to Click the select element. Does the select element have any events on it? Check with the browser tools (press the F12 key). If so, this shows how to trigger the 'change' event on the element with dispatchEvent:
Code:
    Dim evtChange As Object
    Set evtChange = HTML.createEvent("HTMLEvents")
    evtChange.initEvent "change", True, False
    
    Dim drp As HTMLSelectElement
    Set drp = HTML.getElementById("c12ssdrdq")
    drp.Click
    drp.selectedIndex = 2
    drp.dispatchEvent evtChange
Please put VBA code inside CODE tags - click the # icon in the message editor.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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