IE按钮单击VBA

时间:2015-05-28 15:02:34

标签: excel vba excel-vba button

无法在此网站上通过VBA点击“开始”按钮:https://finra-markets.morningstar.com/BondCenter/BondDetail.jsp?ticker=C631551&symbol=RDS4242315

最终会想要循环代码。应该很简单......只是不能得到这个。

Sub Macro1()
 'we define the essential variables
Dim ie As Object
Dim acct
Dim button

   Set Rng = Range("B4:B4")

Set Row = Range(Rng.Offset(1, 0), Rng.Offset(1, 0).End(xlDown))

For Each Row In Rng

   'add the "Microsoft Internet Controls" reference in your VBA Project indirectly
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .Visible = True
    .navigate ("https://finra-markets.morningstar.com/BondCenter/BondDetail.jsp?ticker=C631551&symbol=RDS4242315")
    While ie.ReadyState <> 4
        DoEvents
    Wend
    Set Cusip = .document.getElementById("ms-finra-autocomplete-box") 'id of the username control (HTML Control)
        Cusip.Value = Range("B" & Row.Row).Value



      ie.document.getElementsByTagName("submit").Click



End With

Next Row
End Sub

1 个答案:

答案 0 :(得分:0)

按钮的标记名称不是&#34;提交&#34;但是&#34; INPUT&#34; ......&#34;提交&#34;是类型。

但请注意,还有更多的INPUT元素,因此你的getElementsBy ...将返回一个集合,你需要进一步挖掘才能找到正确的元素,例如通过检查重要属性。

实施例

' ...

Set ECol = ie.document.getElementsByTagName("input")
For Each IFld In ECol
    If IFld.getAttribute("class") = "button_blue autocomplete-go" Then
        IFld.Click
        Exit For
    End If
Next IFld

' ...