简体   繁体   English

双击按钮Internet Explorer Excel VBA

[英]Double click button Internet Explorer Excel VBA

I am trying to simulate double clicking on an object in internet explorer. 我试图模拟双击Internet Explorer中的对象。

Here is the HTML code: 这是HTML代码:

<tr class="selected lead" style="height: 19px;">
<td class="sort-column" style="width: 1200px; line-height: 17px; text-indent: 19px;">
<img class="bi-tree-view-expand-icon" alt="" src="/resource/image/bid/triangle_collapsed_16.png">
<img class="icon" alt="" src=" /resource/image/bid/folder_closed_16.png">
My Content</td>
<td class="horizontal-filler" style="width: 100px;">&nbsp;</td></tr>

And the VBA code (which is currently working): 和VBA代码(目前正在运行):

For Each Btn In IE.document.getElementsByClassName("sort-column")
    If Btn.innerText = "My Content" Then
        Btn.Click
        Exit For
    End If
Next Btn

I can see the code pressing my button, but what I need is a double click of the button. 我可以看到按下按钮的代码,但是我需要双击按钮。 Any help is greatly appreciated. 任何帮助是极大的赞赏。 Thanks! 谢谢!

I spent some time on this and couldn't find a universal answer. 我花了一些时间,找不到一个普遍的答案。 It seems any particular method that fires synthetic events may not work depending on a browser's preferred method, control inheritance, and other factors. 似乎触发合成事件的任何特定方法都可能不起作用,这取决于浏览器的首选方法,控件继承和其他因素。

Assuming the event is supported, initialized, and has a listener then one of these may work for you. 假设该事件受支持,已初始化并且具有侦听器,则其中一种可能对您有用。

If your using Chrome, Firefox, or IE 9 and below 如果您使用的是Chrome,Firefox或IE 9及更低版本

Btn.FireEvents("ondblclick")

Except IE 8 which reportedly wants focus on the object 据报道,除了IE 8希望专注于该对象

Btn.Focus
Btn.FireEvents("ondblclick")

And if you're on IE 10+ and above then you'll be more successful with: 如果您使用的是IE 10+及更高版本,则在以下方面您会更加成功:

Btn.dispatchEvent("ondblclick")

I'll be back after building a project to try these out. 我会在建立一个项目来尝试这些之后回来。 In the meantime I hope this points you in a helpful direction. 同时,我希望这会为您指明一个有用的方向。

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

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