vba"错误91"当试图点击网页上的按钮时

时间:2016-03-16 17:00:03

标签: javascript html vba

我无法弄清楚为什么我在下面的代码片段中收到错误91。任何帮助深表感谢。

 Dim htmldoc As MSHTML.IHTMLDocument 'Document object
 Dim loa

    Set htmldoc = .document
    Set loa = htmldoc.frames("content").document.getElementsByname("SpreadsheetClicked") 
        loa.getElementsByTagName("input")(0).Click `**'error 91 block variable not set`**

编辑html以包含整个来源: 在底部,您将看到顶行和底行按钮的输入标记。

FRAME src="/cgi-bin/webplus.dll?script=/woa/woa-home-frameset.wml" name=content>

<CENTER><SPAN id=oContentWait style="DISPLAY: none"><IFRAME height="100%" src="/cgi-bin/webplus.dll?script=/woa/woa-wait-display.wml" frameBorder=3 width="100%" scrolling=no></IFRAME></SPAN><SPAN id=oContentMain style="DISPLAY: inline">  
<DIV class=filter>
<TABLE class=Outter border=3>
<TBODY>
<TR>
<TD><INPUT type=hidden name=SubmitTP> 
<TABLE class=Inner cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR class=content align=center>
<TD align=right><FONT size=-1>&nbsp;TP</FONT></TD>
<TD noWrap align=left><SELECT onchange="form1.SubmitTP.value = 'True'; form1.submit();" name=TP><OPTION selected>ALL<OPTION>ALL*<A onclick="getUserEntry('TP','TP'); return false;" title="Click here to select multiple Providers" href="#">*</A></TD>
<TD align=right><FONT size=-1>&nbsp;Incr</FONT></TD>
<TD noWrap align=left><SELECT name=Incr><OPTION>ALL<OPTION>DAILY<OPTION selected>HOURLY<OPTION>MONTHLY<OPTION>SMONTHLY<OPTION>VARIABLE<OPTION>WEEKLY<OPTION>YEARLY</OPTION></SELECT></TD>
<TD align=right><FONT size=-1>&nbsp;Peri</FONT></TD>
<TD noWrap align=left><SELECT name=Peri><OPTION selected>ALL<OPTION>FULL_PERIOD<OPTION>OFF_PEAK<OPTION>OFF_PEAK_DAY<OPTION>ON-PEAK<OPTION>ON_PEAK<OPTION>ON_PEAK_DAY<OPTION>WEEKDAY<OPTION>WEEKEND</OPTION></SELECT></TD>
<TD align=right><FONT size=-1>&nbsp;POR</FONT></TD>
<TD </TD>
<TD</TD></TR>
<TR class=content align=center>
<TD </TD>
<TD </A></TD>
<TD align=right><FONT size=-1>&nbsp;Class</FONT></TD>
<TD </TD>
<TD align=right><FONT size=-1>&nbsp;Win</FONT></TD>
<TD noWrap align=left><SELECT name=Win><OPTION selected>ALL<OPTION>EXTENDED<OPTION>FIXED<OPTION>ROLLING<OPTION>SLIDING</OPTION></SELECT></TD>
<TD align=right><FONT size=-1>&nbsp;POD</FONT></TD>
<TD </A></TD>
<TD colSpan=2 noWrap align=left><FONT size=-1>Daylight Savings <INPUT type=checkbox value=1 name=UseDST> </FONT><FONT size=-1>Show Active Data <INPUT CHECKED type=checkbox value=1 name=ShowActive> </FONT></TD></TR>
<TR class=content align=center>
<TD align=right><FONT size=-1>&nbsp;Ref</FONT></TD>
<TD align=left><INPUT style="HEIGHT: 0.5cm" maxLength=12 size=6 name=Posting></TD>
<TD align=right><FONT size=-1>&nbsp;Type</FONT></TD>
<TD </TD>
<TD </TD>
<TD </TD>
<TD align=right><FONT size=-1>&nbsp;Time</FONT></TD>
<TD colSpan=4 noWrap align=left><SELECT name=TimeFilter> <OPTION value=StartTime>Start<OPTION value=StopTime>Stop<OPTION value=OfferStartTime>Offer Start<OPTION value=OfferStopTime>Offer End<OPTION selected value=Active>Active<OPTION value=UpdateTime>Update</OPTION></SELECT> <SELECT style="WIDTH: 160px" name=TSpan> <OPTION value=Today>Today<OPTION selected value="This Hour">This hour<OPTION value="This Hour Forward">This hour fwd<OPTION value="Next Hour">Next hour<OPTION value="After Next Hour">After next hour<OPTION value=Yesterday>Yesterday<OPTION value=Tomorrow>Tomorrow<OPTION value="This Week">This week<OPTION value="Last Week">Last week<OPTION value="Next Week">Next week<OPTION value="This Month">This month<OPTION value="Last Month">Last month<OPTION value="Next Month">Next month<OPTION value="Today Forward">Today forward<OPTION value="Tomorrow Forward">Tomorrow fwd<OPTION value="All Past">Before today</OPTION></SELECT> &nbsp;&nbsp;<INPUT class=btn1 type=submit value=" Enter " name=EnterClicked> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV><INPUT type=hidden name=NewColumnList> <INPUT type=hidden name=NewQueryList>
<SCRIPT language=JavaScript>
    window.document.form1.NewColumnList.value = ''
</SCRIPT>

<TABLE border=0>
<TBODY>
<TR vAlign=top>
<TD align=center><INPUT disabled class=btn1 type=button value="New Posting" name=NewClicked> 
<TD align=center><INPUT onclick="openChild( '/cgi-bin/webplus.dll?script=/woa/woa-transoffering-summary-popup-userrange.wml', 'UserRange', 500, 150, true );" class=btn1 type=button value="User Range" name=UserRangeClicked></TD>
<TD align=center><INPUT onclick=showTransofferingSummaryColumnsPopup() class=btn1 type=button value=Columns name=ColumnsClicked></TD>
<TD align=center><INPUT onclick="window.location.href='/cgi-bin/webplus.dll?script=/woa/woa-path-atc-hourly-summary.wml'" class=btn1 type=button value="Hourly Summary" name="NEW ATC"> </TD>
<TD align=center><INPUT onclick=SaveQuery(); class=btn1 type=button value="Save Query"></TD>
<TD align=center><SELECT onchange=SelectQuery(); name=SelectedQuery> <OPTION selected></OPTION> <OPTION>Configure</OPTION></SELECT> </TD><INPUT type=hidden name=NewQueryChanged> </TR>
<TR>
<TD colSpan=6 align=center><INPUT onclick="openChildWindow( '/cgi-bin/webplus.dll?script=/woa/woa-atcmonitordetail.wml&amp;Allow=1', 'ATCMonitorDetail', 500, 150, true );" class=btn1 type=button value="ATC/TTC Monitor" name=ATCMonitorAlarmDetailClicked> <INPUT onclick=OpenSpreadsheetView() class=btn1 type=button value=Spreadsheet name=SpreadsheetClicked> <INPUT onclick=DownloadCSV() class=btn1 type=button value="Download CSV" name=DownloadCSVClicked> </TD></TR></TBODY></TABLE><FONT color=#ff0000>Selected time range: <B>2016-03-18 10:00:00 PD</B> to <B>10:59:00 PD</B> </FONT><INPUT type=hidden value=2012-01-19 name=SelectedUserRangeStart> <INPUT type=hidden value=2012-01-20 name=SelectedUserRangeEnd> <BR><TR><TD>&nbsp;</TD></TR> 

1 个答案:

答案 0 :(得分:0)

尝试像这样声明loa

Dim loa As Object

编辑#1:

以下是如何循环浏览html文档以查找名为&#34; content&#34;的框架:

Set htmldoc = .document
Set frmes = htmldoc.getElementsByTagName("frame")
    For Each frme In frmes
        If frme.Name = "content" Then
               Set loa = frme.document.getElementsByTageName("input")(1)
               Or
               Set load = frme.document.getElementsByName("SpreadsheetClicked")
               loa.click
        End if
    Next resultClass

请告诉我这是否有助于您更进一步

编辑#2:应该这样做

Dim htmldoc As MSHTML.IHTMLDocument 'Document object
Dim loa As Object, loa2 As Object

    Set htmldoc = .document
    Set loa = htmldoc.frames(6)
    Set loa2 = loa.document.getElementsByTagName("input")(1)
    loa2.Click

编辑#3:好的,我想我现在想出了如何正确导航框架中的标签

Dim htmldoc As MSHTML.IHTMLDocument 'Document object
Dim loa As Object, loa2 As Object

    Set htmldoc = .document
    Set loa = htmldoc.frames(6).document.all.tags("input").Item(1)
    loa.Click