0
votes

I've been trying to select 1 of 2 radio buttons in IE11 using Excel VBA. Here is the HTML:

<BODY><TABLE cellSpacing=0 cellPadding=0 width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE height=18 cellSpacing=0 cellPadding=0 width="100%" align=center bgColor=#336699 border=0>
<FORM method=post name=ChangeAirportForm action=/mas/ChangeAirportAction.do>
<TBODY>
<TR class=trH align=center>
<TD vAlign=top width="1%"><IMG border=0 src="https://mas.bafs.co.th/mas/include/images/l.gif" width=8 height=18></TD>
<TD width="10%">&nbsp;</TD>
<TD width="29%">Airport Site Code</TD>
<TD width="29%">Airport Site Name</TD>
<TD width="30%">&nbsp;</TD>
<TD vAlign=top width="1%" align=right><IMG border=0 src="https://mas.bafs.co.th/mas/include/images/r.gif" width=8 height=18></TD></TR>
<TR class=trA align=center>
<TD>&nbsp;</TD>
<TD><INPUT style="BORDER-TOP: 0px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px" CHECKED type=radio value=1 name=airport></TD>
<TD>DMK</TD>
<TD>Donmueang</TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD></TR>
<TR class=trB align=center>
<TD>&nbsp;</TD>
<TD><INPUT style="BORDER-TOP: 0px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px" type=radio value=4 name=airport></TD>
<TD>BKK</TD>
<TD>Suvarnabhumi</TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD></TR></FORM></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY>
</html>

The radio button I wish to select is the type=radio value=4 name=airport

Below is my meagre attempt which didn't work.

Sub select_radio_button()

Dim sUrl As String: sUrl = xxxxx

Dim oIE As New SHDocVw.InternetExplorer

oIE.Visible = True

oIE.Navigate sUrl

Dim oIEdoc As Object

Set oIEdoc = oIE.Document

Dim oColl as Object

Set oColl = oIEdoc.getElementsByTagName("input")

Dim obj as Object

For Each obj in oColl

If obj.getAttribute("type") = "radio" And obj.getAttribute("value") = 4 Then obj.Click

Next obj

End Sub

1

1 Answers

0
votes

You said that your attempt is not working. I am not sure what exactly is not working as you did not provide any detailed information about it.

I tried to test the code on my side and it works fine. It selects the correct radio button.

I have not modified anything in your code. I just tried to run it.

Output:

enter image description here

I suggest again try to test the issue on your side. If still issue persists then please try to provide detailed information about the issue.

Try to inform us what OS build and which version of the Excel you are using? Inform us, if you are getting any error or warning messages. It may help us to understand the issue in a better way.