简体   繁体   English

使用VBA单击IE按钮

[英]IE button click with VBA

Can't get the "GO" button to click via VBA on this site: https://finra-markets.morningstar.com/BondCenter/BondDetail.jsp?ticker=C631551&symbol=RDS4242315 无法获取“ GO”按钮以通过VBA在此站点上单击: https : //finra-markets.morningstar.com/BondCenter/BondDetail.jsp?ticker=C631551&symbol=RDS4242315

Will eventually want to loop code. 最终将要循环代码。 Should be simple...just can't get this one. 应该很简单...简直无法做到这一点。

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

The tag name of your button is not "submit" but "INPUT" ... "submit" is the type. 按钮的标签名称不是“ submit”,而是“ INPUT” ...“ submit”。

But watch out, there are more INPUT elements, so your getElementsBy... will return a collection and you need to further dig to find the correct one, eg by checking a significant attribute. 但是请注意,还有更多的INPUT元素,因此您的getElementsBy ...将返回一个集合,您需要进一步挖掘以找到正确的集合,例如,通过检查重要属性。

Example

' ...

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

' ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM