【问题标题】:Trying to select Radio Button in IE11 with Excel VBA尝试使用 Excel VBA 在 IE11 中选择单选按钮
【发布时间】:2020-11-21 04:36:38
【问题描述】:

我一直在尝试使用 Excel VBA 在 IE11 中选择 2 个单选按钮中的 1 个。 这是 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>

我希望选择的单选按钮是type=radio value=4 name=airport

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

【问题讨论】:

    标签: html excel vba internet-explorer


    【解决方案1】:

    您说您的尝试无效。我不确定究竟是什么不起作用,因为您没有提供任何有关它的详细信息。

    我尝试测试我这边的代码,它工作正常。它选择了正确的单选按钮。

    我没有修改您的代码中的任何内容。我只是尝试运行它。

    输出:

    我建议再次尝试在您这边测试该问题。如果问题仍然存在,请尝试提供有关该问题的详细信息。

    请告诉我们您使用的是什么操作系统以及您使用的 Excel 版本?如果您收到任何错误或警告消息,请通知我们。它可以帮助我们更好地理解问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      相关资源
      最近更新 更多