如何激活JavaScript" onclick"通过Excel VBA活动?

时间:2017-10-30 02:33:05

标签: javascript html vba

我试图通过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&#34; onclick&#34;他们给了我运行时错误。

1 个答案:

答案 0 :(得分:1)

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

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

感谢所有帮助和提示!