如何调用VBA javascript函数 [英] How to call javascript function in VBA
问题描述
我需要通过传递一个IE确认'OK'/'取消'弹出消息。
我有我的VBA脚本运行的JavaScript函数有问题。
参见下面的JavaScript codeS
函数ConfirmSave()
{
VAR OK =确认(你确定所有文件和信息都保存之前连接并正确吗?');如果(OK)
返回true;
其他
返回false;
}
功能submitbutton_click(){
。的document.getElementById('FileAttachement2_hdnButtonFlag')值=SAVE;
变种提交按钮=的document.getElementById('cmdDownSave');
变种uploadobj =的document.getElementById('FileAttachement2_Uploader1');
如果(!window.filesuploaded)
{
如果返回false(ConfirmSave()!);
如果(uploadobj.getqueuecount()大于0)
{ uploadobj.startupload();
}
其他
{
// VAR uploadedcount = parseInt函数(submitbutton.getAttribute(ITEMCOUNT))|| 0;
//如果(uploadedcount大于0)
// {
返回true;
//}
//警报(请浏览上传文件);
}
返回false;
}
window.filesuploaded = FALSE;
返回true;
}
在手动过程中,当我点击保存按钮时,页面会弹出一个确认消息框,我的宏将停止运行时弹出出现,除非它已被点击。
这里是code我都试过了,点击保存按钮,
设置ElementNameV = HTMLDoc.getElementsByName(cmdsave)
ElementNameV(0)。点击
我的removeAttribute使用和setAttribute,弹出消息消失,也尝试过,但它不会上传那是因为我需要preSS的在确认消息框OK将出现在点击保存文件按钮,启动文件上传
ElementNameV(0).removeAttribute(onclick事件)
ElementNameV(0).setAttribute的onclick,返回true
ElementNameV(0)。点击
我试着用下面的脚本运行的JavaScript功能,但它也显示了确认弹出消息框。
呼叫HTMLDoc.parentWindow.execScript(submitbutton_click())
您应该能够与其中一个简单的返回true覆盖 ConfirmSave
功能:
HTMLDoc.parentWindow.execScriptwindow.ConfirmSave =函数(){返回true;};
或
HTMLDoc.parentWindow.execScriptwindow.confirm =函数(){返回true;};
甚至
HTMLDoc.parentWindow.evalwindow.confirm =函数(){返回true;};
单击此按钮前的运行。
在IE11测试和工程
I need to by pass an IE confirm 'OK'/'Cancel' pop-up message. I have a problem running a javascript function in my vba script.
see below for the javascript codes
function ConfirmSave()
{
var Ok = confirm('Are you sure all Documents and Information are attached and correct before saving?');
if(Ok)
return true;
else
return false;
}
function submitbutton_click() {
document.getElementById('FileAttachement2_hdnButtonFlag').value = "SAVE";
var submitbutton = document.getElementById('cmdDownSave');
var uploadobj=document.getElementById('FileAttachement2_Uploader1');
if(!window.filesuploaded)
{
if (!ConfirmSave()) return false;
if(uploadobj.getqueuecount()>0)
{
uploadobj.startupload();
}
else
{
//var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;
//if(uploadedcount>0)
//{
return true;
//}
//alert("Please browse files for upload");
}
return false;
}
window.filesuploaded=false;
return true;
}
In manual process, when I click the save button, the page will pop-up a confirm message box, and my macro will stop running when the pop-up appears unless it has been clicked.
here is the code I have tried, to click the save button,
Set ElementNameV = HTMLDoc.getElementsByName("cmdsave")
ElementNameV(0).click
I also tried using removeattribute and setattribute, the pop-up message disappear but it doesn't upload the file that is because I need to press the 'OK' in confirm message box that will appear upon clicking the save button to start the file uploading.
ElementNameV(0).removeAttribute ("onclick")
ElementNameV(0).setAttribute "onclick", "return true"
ElementNameV(0).click
I tried running the javascript function using below script but it also show the confirm pop-up message box.
Call HTMLDoc.parentWindow.execScript("submitbutton_click()")
You should be able to overwrite the ConfirmSave
function with one which simply returns true:
HTMLDoc.parentWindow.execScript "window.ConfirmSave = function(){return true;};"
or
HTMLDoc.parentWindow.execScript "window.confirm = function(){return true;};"
or even
HTMLDoc.parentWindow.eval "window.confirm = function(){return true;};"
Run that before clicking the button.
Tested and works in IE11
这篇关于如何调用VBA javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!