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:
Any help is really appreciated.
Thanks!
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!