VBA to select HTML Drop Down

bevymart

New Member
Joined
Jul 30, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hey Folks,

Seen a few solutions on here but still stuck on this. .I'm trying to get a solution to set a drop down field that isn't named

1596158038643.png


I'm trying to get it to select "Moving" or "Storage" depending on the customer type but I'm not having any luck

Any ideas or help would be greatly appreciated
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to MrExcel forums.

Try something like this. Needs MS HTML Object Library reference and IE is the InternetExplorer object with the webpage loaded.
VBA Code:
    Dim HTMLdoc As HTMLDocument
    Dim selectElements As IHTMLElementCollection
    Dim selectElement As HTMLSelectElement
    Dim i As Long
    
    Set HTMLdoc = IE.document
    Set selectElements = HTMLdoc.getElementsByTagName("SELECT")
    Set selectElement = Nothing
    i = 0
    While i < selectElements.Length And selectElement Is Nothing
        If InStr(selectElements(i).innerHTML, "Select Customer Type") Then Set selectElement = selectElements(i)
        i = i + 1
    Wend
    If Not selectElement Is Nothing Then
        selectElement.Value = "Moving"
    Else
        MsgBox "Not found"
    End If
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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