Using VBA to select option from IE dropdown menu

Scorsese

New Member
Joined
Dec 22, 2016
Messages
3
Hello mr excel community!,
Im a newbie to VBA, I usually work with VBA to create simple excel macros, but right now, I am working on a new project where I am opening a webpage and filling out some fields, I managed to fill textboxes, but right now I am having trouble to select options from drop down lists and checking/selecting radio buttons.


This is the html code refering to the dropdown list:

[HTML code for drop down list][1]
[1]: https://i.stack.imgur.com/FAI3U.jpg



And this one is the code for one of the radio buttons:
[HTML code for radio button][2]
[2]: https://i.stack.imgur.com/ElDJf.jpg


Sorry for the images, I could not found a way to copy more than one line of HTML code:(


This is my code so far:

Code:
    Sub w()
    '
    ' w Macro
    '
    ' Keyboard Shortcut: Ctrl+w
    '
    'pick ups cell b2 value
    Dim cellvalue As String
    cellvalue = ActiveSheet.Cells(1, 2)
    
    
    Dim HTMLDoc As HTMLDocument
    Dim oBrowser As InternetExplorer
    ''Sub Login_2_Website()
    
    Dim oHTML_Element As IHTMLElement
    Dim sURL As String
    
    On Error GoTo Err_Clear
    sURL = cellvalue '
    Set oBrowser = New InternetExplorer
    oBrowser.Silent = True
    oBrowser.timeout = 60
    oBrowser.navigate sURL
    oBrowser.Visible = True
    
    Do
    ' Wait till the Browser is loaded
    Loop Until oBrowser.readyState = READYSTATE_COMPLETE
    
    Set HTMLDoc = oBrowser.document
    
    'fill email response address
    HTMLDoc.all.emailAddresses.Value = ActiveSheet.Cells(5, 3)
    
    'fill shipment reference number
    HTMLDoc.all.filingRefNumber.Value = ActiveSheet.Cells(5, 7)
       
    'fill dropbox option
    'NOT WORKING    
    If Not VBA.IsNull(ie.document.getElementById("select2-drop-mask")) Then
        Dim htmlSelect
        Set htmlSelect = ie.document.getElementById("select2-drop-mask")
        htmlSelect.Value = 4 - POSTDEPARTURE
    Else
        MsgBox "Element 'select2-drop-mask' was not found", vbExclamation
    End If  
    
  
    'SELECT RADIO BUTTON
    ' NOT WORKING
   


    ie.document.getElementsByName("shipmentInfo.routedExpTransactionInd.stringFiEld").Item(1).Checked = True




 
    
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("Login")
    If oHTML_Element.Type = "Login" Then oHTML_Element.Click: Exit For
    Next
    
    ' oBrowser.Refresh ' Refresh If Needed
    Err_Clear:
    If Err <> 0 Then
    'Debug.Assert Err = 0
    Err.Clear
    Resume Next
    End If
    End Sub










Any help is really appreciated.


Thanks!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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