【问题标题】:How to activate JavaScript "onclick" Event via Excel VBA?如何通过 Excel VBA 激活 JavaScript“onclick”事件?
【发布时间】:2017-10-31 12:05:14
【问题描述】:

我正在尝试通过 VBA excel 脚本单击网页上的按钮,但在使用以下代码时出现运行时错误:

objIE.document.getElementById("e-actions-commonmasthead-mail").Click

我试图从页面中获取的元素使用以下 HTML 列出:

<td id="e-actions-commonmasthead-mail"
    class="s-cell-center s-toolbarcell-left s-toolbar-text s-toolbarcell-selected" 
    title="Mail" toolbarside="left" toolbarindex="0" 
    com_ibm_dwa_ui_toolbar_overflowed="false"

 onmouseover="AAA.DSq.EKc.prototype.EYl['e-actions-commonmasthead:Ebx'].EEu(event, this);"
  onmouseout="AAA.DSq.EKc.prototype.EYl['e-actions-commonmasthead:Ebx'].EEu(event, this);"
     onclick="AAA.DSq.ELU(event, 'e-actions-commonmasthead', 'Gqj', {area:'mail'});" 

  unselectable="on" style="-moz-box-sizing:border-box;-webkit-user-select:none;">

<img align="center" border="0" width="16" height="16" 
     id="e-actions-commonmasthead-mail-icon" 
     class="s-toolbaricon-notext" 
     src="/iNotes/Forms9.nsf/transparent.gif?OpenFileResource&amp;MX&amp;TS=20160816T154745,21Z" 
     xoffset="" yoffset="" 
     style="background-image: url(&quot;/iNotes/Forms9.nsf/sprite_masthead.png?OpenFileResource&amp;MX&amp;TS=20160816T154745,21Z&quot;); 
            background-position: -17px 0px;">
</td>

我已经尝试过 Click 和 FireEvent "onclick",但它们给了我运行时错误。

【问题讨论】:

  • 你遇到了什么错误?
  • 我收到运行时错误“424”,需要对象。
  • 检查您发布的代码行中的每个对象,看看哪个是Nothing。发布更多代码会很有用。

标签: javascript html vba


【解决方案1】:

好的,我想通了。我需要通过以下代码手动调用 onclick 脚本:

 Call objIE.document.parentWindow.execScript("AAA.DSq.ELU(event, 'e-actions-commonmasthead', 'Gqj', {area:'mail'})", "JavaScript")   

感谢所有帮助和提示!

【讨论】:

    猜你喜欢
    • 2012-06-05
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多