VBA code to select item from drop-down on a website

Zsir22

New Member
Joined
Aug 24, 2016
Messages
2
Hello All,

I am struggling to select the value from a drop down list on web page by using VBA.
My code so far:


Code:
Sub Select()


Dim objIE As InternetExplorer


Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://www.moneygram.com/wps/portal/moneygramonline/home/estimator"
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
objIE.Document.forms("estimatorForm").getElementsByTagName("select")("fCountry").Value = "ALB"
objIE.Document.forms("estimatorForm").FireEvent ("onchange")

It seems that it picks the required value from the list, however does not select it in the drop-down...
Web page code is the following:





<label>From</label>

Choose a country
<select title="Choose a country to send from" name="fCountry" class="styled countryA "><option value="" selected="selected">Choose a country</option><option value="AFG" currency="[{" code":"afn","name":"afghan="" afghani"},{"code":"usd","name":"us="" dollar"}]"="">AFGHANISTAN</option><option value="ALB" currency="[{" code":"eur","name":"euro"}]"="">ALBANIA</option><option value="DZA" currency="[{" code":"dzd","name":"algerian="" dinar"}]"="">ALGERIA</option></select>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Some webpages are obviously built better than others. This webpage has another triggered event that is hard to actually capture by looking at the HTML. If you hit the "Estimate" button, however, you can see that the value "ALBANIA" is actually being recognized by the website, even though it's not showing.

You'd have to enter in each value for the 5 fields using this same method, and then click the "Estimate" button
 
Upvote 0
Thank you for an advice. I tried to do the following, however, I ran into the problem of identifying the button... The HTML code for it gives only this:

<a href="#" class="redEstimate"/>

Another issue is, that even if run the following macro, and then click the button manually, it gets me to an error message: "We are unable to process your request at this time."


Code:
Sub Select()


Dim objIE As InternetExplorer


Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://www.moneygram.com/wps/portal/moneygramonline/home/estimator"
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: LoopobjIE.Document.forms("estimatorForm").getElementsByTagName("select")("fCountry").Value = "ALB"
objIE.Document.forms("estimatorForm").FireEvent ("onchange")
    
objIE.Document.forms("estimatorForm").getElementsByTagName("select")("fCurrency").Value = "EUR"
objIE.Document.forms("estimatorForm").FireEvent ("onchange")
    
objIE.Document.forms("estimatorForm").getElementsByTagName("select")("dCountry").Value = "ALB"
objIE.Document.forms("estimatorForm").FireEvent ("onchange")
    
objIE.Document.forms("estimatorForm").getElementsByTagName("select")("sService").Value = "WILL_CALL:    EUR"
objIE.Document.forms("estimatorForm").FireEvent ("onchange")
 
Upvote 0

Forum statistics

Threads
1,215,308
Messages
6,124,178
Members
449,146
Latest member
el_gazar

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