如何通过Excel VBA单击JavaScript确认弹出窗口

问题描述:

我正在使用InternetExplorer对象与网页进行交互,填写表单以及所有内容。有时,单击页面上的按钮后,会弹出一个对话框,要求确认操作。如何单击弹出窗口中的确定按钮?

I am using the InternetExplorer object to interact with a web page, filling out a form and all that. At one point, after clicking a button on a page a Dialog box pops up asking to confirm the operation. How do I click the OK button in the popup?

相关的JavaScript和HTML为:

The relevant JavaScript and HTML is:

function CheckMakeCurr() 
{
    if(confirm('Are you sure you want to set the\n "Last Rebalance Date" to today?')) 
        { return true; }
    else
        { return false; }
};

...

<INPUT onclick="return CheckMakeCurr()" class=button type=submit value="Make Current" name=updaterebaldt>

Excel vba代码为:

The Excel vba code is:

Dim oInput As IHTMLInputElement

' Initialize oInput.
...

' Click oInput.
oInput.click

' The confirm box comes up. What now?


在单击链接之前,请删除 onclick 处理程序,它会触发弹出窗口:

Before you click the link, remove the onclick handler which triggers the popup:

oInput.onclick = ""
oInput.click