使用VBA在HTML表格中单击表格行 [英] Clicking Table Row in HTML Table using VBA

查看:89
本文介绍了使用VBA在HTML表格中单击表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VBA在Excel中创建自动化工具,该工具运行并从网站门户下载数据库查询.该工具几乎可以完全起作用,但是我无法确定的第一步是查询选择.

I am attempting to create an automation tool in Excel using VBA which runs and downloads a database query from a website portal. The tool is almost completely functional, but the one step I just cannot figure out is the query selection.

一旦用户在门户中搜索了查询,就会将适用的查询放入HTML表中的行中.用户可以通过两种方式运行查询:双击一行或单击一行,然后单击门户中的另一个按钮.我的困难在于,即使经过数小时的研究,我仍无法执行这两种策略.

Once the user has searched for the query in the portal, applicable queries are put into rows within a HTML table. There are two ways a user can run a query: double-click a row OR click a row and then click another button in the portal. My difficulty is that I am unable to preform either of these tactics even after hours of research.

表的第一行的HTML代码(这是所需的查询)如下所示.我包含了td标签,因此您还可以看到该行中的单元格.

The HTML code for the first row of the table (which is the desired query) is seen below. I included the td tags so you could also see the cells within the row.

<TABLE class="x-grid-table x-grid-table-resizer" style="WIDTH: 1867px" cellSpacing=0 cellPadding=0 border=0>
    <TBODY>
        <TR class="x-grid-row " _nodup="30806" viewIndex="0" viewRecordId="ext-record-17" boundView="objectgridview">
            <TD class=" x-grid-cell x-grid-cell-gridcolumn-1085   x-grid-cell-first" rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">
                    <SPAN class="grid-icon view-16"></SPAN>
                    <SPAN>QUERYNAME</SPAN> 
                </DIV>
            </TD>
            <TD class=" x-grid-cell x-grid-cell-gridcolumn-1086   " rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">QUERYTYPE</DIV></TD>
            <TD class=" x-grid-cell x-grid-cell-gridcolumn-1087   " rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">QUERYDESCRIPTION</DIV>
            </TD>
            <TD class=" x-grid-cell x-grid-cell-gridcolumn-1088   " rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">QUERYLIBRARY</DIV>
            </TD>
            <TD class=" x-grid-cell x-grid-cell-gridcolumn-1089   " rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">QUERYOWNER</DIV>
            </TD>
            <TD class=" x-grid-cell x-grid-cell-datecolumn-1090    x-grid-cell-last" rowSpan="1" colSpan="1">
                <DIV class="x-grid-cell-inner " style="TEXT-ALIGN: left">QUERYDATE</DIV>
            </TD>     
        </TR>
    </TBODY>
</TABLE>

我还查看了Chrome中的HTML,唯一的不同之处在于,当鼠标指针位于该行上时,tr类名切换为"x-grid-row x-grid-row-over",而"x-单击该行时,"grid-row x-grid-row-selected x-grid-row-over-focused".

I also looked at the HTML in Chrome, with the only other difference being that the tr classname switches to "x-grid-row x-grid-row-over" when the mouse cursor is over that row and "x-grid-row x-grid-row-selected x-grid-row-over-focused" when the row is clicked.

如前所述,我尝试了多种方法来单击此行.我能够使用getElementsByTagName来标识row/table/others元素,但是即使找到了这个,我仍然找不到成功.

As mentioned I have tried a number of methods to click on this row. I was able to use getElementsByTagName is identify the row/table/others element, but even after finding this I still couldn't find success.

下面使用了一些代码行.

Some of the code lines that I have used are below.

IE.document.getElementsByTagName("tr")(42).Classname = "x-grid-row x-grid-row-selected x-grid-row-focused"
IE.document.getElementsByTagName("table")(20).Rows(0).Click
IE.document.getElementsByTagName("tr")(42).getElementsByTagName("td")(3).getElementsByTagName("div")(0).Click
IE.document.getElementsByTagName("tr")(42).getElementsByTagName("td")(3).Selected = True
Call IE.document.getElementsByTagName("tr")(42).execScript("mouseup()", "Javascript")

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys ("-{F10}")
WshShell.SendKeys "{DOWN}"
WshShell.SendKeys "{ENTER}"

我希望有人能够提供一些我所缺少的知识.谢谢!

I am hoping someone might be able to provide some knowledge that I am missing. Thanks!

推荐答案

您尝试将属性选择器与FireEvent结合使用吗?

Did you try using combination of attribute selectors with FireEvent?

ie.document.querySelector("[_nodup='30806'][viewindex='0']").FireEvent "ondblclick"

这将定位第一行并双击.这些属性也会改变吗?

This targets the first row and use a double click. Do those attributes also change?

这篇关于使用VBA在HTML表格中单击表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆