如何在 VBA/VBScript 中执行 onclick 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12583405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do onclick event in VBA/VBScript
提问by Jason Bayldon
<td class="highlightTab" id="tabnew" style="background-color: red; color: yellow;" onmouseover="setBgColor('tabnew')" onmouseout="setHighOrgBgColor('tabnew','highlightTab')">
<a class="highlightTabLabel" onclick="parent.MainFrame.request('ref_back','')" href="Javascript:void(0)">
I am still trying to learn excel automation with web pages. I am trying to force the onclick using FireEvent (using both click and fireevent, but neither are working atm) and I cannot figure this out:
我仍在尝试使用网页学习 excel 自动化。我正在尝试使用 FireEvent 强制 onclick(同时使用 click 和 fireevent,但两者都无法在 atm 中工作),但我无法弄清楚:
.getElementById("tabnew").Click
.getElementById("tabnew").FireEvent ("onclick")
Does anyone have any Ideas? I really wish there was more documentation on html object library for use in VBScript/VBA :(
有没有人有任何想法?我真的希望有更多关于 html 对象库的文档用于 VBScript/VBA :(
回答by Harrison Harris
Here's what you're looking for:
这就是你要找的:
document.getElementById("tabnew").attachEvent "onclick",getref("onclick")
document.getElementById("tabnew").attachEvent "onclick",getref("onclick")
First argument is the event ("onclick","onmouseover"... See: http://www.tutorialspoint.com/vbscript/vbscript_events.htm(very bottom of page for list of events)) Second argument is a getref of the name of your sub.
第一个参数是事件(“onclick”、“onmouseover”...参见:http: //www.tutorialspoint.com/vbscript/vbscript_events.htm(事件列表的页面底部))第二个参数是你的子名称。