简体   繁体   English

VBA宏中的运行时错误91以击中网站Excel VBA中的搜索按钮

[英]Run time error 91 in VBA macro to hit search button in website Excel VBA

This little script is supposed to go to the website http://finra-markets.morningstar.com/BondCenter/Default.jsp 这个小脚本应该转到网站http://finra-markets.morningstar.com/BondCenter/Default.jsp

Insert under the tab "Search" inside the "Symbol/Cusip" box the number 111320AE7 and click on the "Show Results" button to get the results. "Symbol/Cusip"框内的“ Search”选项卡下插入编号111320AE7 ,然后单击"Show Results"按钮以获取结果。

Sub SearchSite()
    Dim beta
    Dim objIE As InternetExplorer
    Set objIE = New InternetExplorer

    objIE.Visible = True
    objIE.navigate "http://finra-markets.morningstar.com/BondCenter/Default.jsp"

    Do While objIE.Busy = True Or objIE.readyState <> 4
        DoEvents
    Loop
    objIE.document.getElementById("firscreener-cusip").Value = "111320AE7"

    Set beta = objIE.document.getElementsByClassName("ms-finra-advanced-search-btn")(1)

    beta.Click

    Do While objIE.Busy = True Or objIE.readyState <> 4
        DoEvents
    Loop
    'objIE.Quit

End Sub

I get Run-time error 91: Object variable or With block variable not set 我收到运行时错误91: Object variable or With block variable not set

The problem appears to be the beta.click line 问题似乎是beta.click

I would appreciate some help. 我将不胜感激。 Thanks a lot. 非常感谢。

Beta is referencing the div that contains the buttons. Beta正在引用包含按钮的div。 The element arrays are base 0. They start at 0 not 1. 元素数组以0为底。它们从0而不是1开始。

Sub SearchSite()
    Dim beta, buttons, btnReset, btnSubmit
    Dim objIE As InternetExplorer
    Set objIE = New InternetExplorer

    objIE.Visible = True
    objIE.navigate "http://finra-markets.morningstar.com/BondCenter/Default.jsp"

    Do While objIE.Busy = True Or objIE.readyState <> 4

    Loop

    objIE.document.getElementById("firscreener-cusip").Value = "111320AE7"

    Set beta = objIE.document.getElementsByClassName("ms-finra-advanced-search-btn")(0)

'   <div class="ms-finra-advanced-search-btn">
'       <input class="button_blue" value="CLEAR CRITERIA" type="reset">
'       <input class="button_blue" value="SHOW RESULTS" type="submit">
'    </div>

    Set buttons = beta.GetElementsByTagName("input")

    WScript.Echo buttons(0).outerHTML

'   <input class="button_blue" value="CLEAR CRITERIA" type="reset">

    Set btnReset = buttons(0)

'    <input class="button_blue" value="SHOW RESULTS" type="submit">

    Set btnSubmit = buttons(0)


    beta.btnSubmit

    Do While objIE.Busy = True Or objIE.readyState <> 4

    Loop
    objIE.Quit

End Sub

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

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