HTML/VBA Click event not firing

2019-04-13 15:25发布

问题:

This is my first time posting a question on StackOverflow. Up until now I have been able to resolve most of my questions via VBA help forums.

My issue is pretty simple. I have an automated data pull in which I need to export data. I have been successful with this in the past, but this one is slightly different.

The HTML for the button I am trying to click to generate the export is this:

  <a id="ReportViewer1_ctl01_ctl05_ctl01" 
    style="font-family: Verdana; font-size: 8pt; color: Gray; text-decoration: none; 
    cursor: default;" href="#" title="Export"
 onmouseout="TextLinkReportViewer1_ctl01_ctl05_ctl01.OnLinkNormal();"
 onmouseover="TextLinkReportViewer1_ctl01_ctl05_ctl01.OnLinkHover();" 
    onclick="if (document.getElementById('ReportViewer1_ctl01_ctl05_ctl00').selectedIndex == 0) return false; 
    if (!ClientToolbarReportViewer1_ctl01.HandleClientSideExport()) __doPostBack('ReportViewer1$ctl01$ctl05$ctl01','');return false;">Export</a>

I have tried several ways to click to no avail.

回答1:

FireEvent is used to trigger the event attached to any element.

IE.document.getElementById("ReportViewer1_ctl01_ctl05_ctl01").click()
IE.document.getElementById("ReportViewer1_ctl01_ctl05_ctl01").FireEvent("onclick")


回答2:

IE.document.getElementById("ReportViewer1_ctl01_ctl05_ctl01").click()