我正在打开一个使用VBA代码的网页,其中包含数据将由用户填写的表单。我有包含数据的excel文件。我写的VBA代码,从excel读取数据,并将其放在网页上。在网页上填写信息后,我点击保存按钮。所有这些工作我都是使用VBA代码完成的,这样它就可以自动完成。我有500个用户的数据,因此我运行了500次循环。它所做的一切都是罚款。
只有一个问题出现了,那就是在网页表单中填写数据后,当我单击保存按钮时,会弹出一条消息“您的数据已成功保存”。它有“确定”按钮。现在我的程序停在这里,需要用户干预才能手动单击“确定”按钮。
有没有什么办法可以使用VBA代码来阻止这个弹出消息框,从而不再需要手动干预?
我也读了网页和为网页写的Javascript。我发现当单击保存按钮时,有一个名为savedetails()
的函数。在这个函数中有一个alert()
函数。示例代码在这里
function saveDetails()
{
/* get details of member*/
---
---
---
---
---
if (xml.status == 200 || window.location.href.indexOf("http") == -1) {
var successCode = "";
alert("Data Saved Successfully");
var tes = xml.responseText;
/* if (successCode == '1') { */
document.webDataForm.submit();
remove_popup();
};
}
htmlColl中每个htmlInput的VBA代码
If Trim(htmlInput.ID) = "btn" Then
If Trim(htmlInput.Name) = "btnfinal" Then
htmlInput.Click 'After this "Data Saved Successfully popup message comes and program need user intervention
temp = htmlInput.getAttribute("onClick")
MsgBox temp
'IE.document.getElementById("clearRelItems").removeAttribute ("o n C l i c k")
'Call iedoc.parentWindow.execScript("window.confirm = function saveBankDetails() {return true}", "JavaScript") // Not worked
'htmlInput.removeAttribute ("onClick") //Not worked
'htmlInput.setAttribute "onClick", "return TRUE" //Not worked
'Application.SendKeys "{ENTER}", True // Not worked
Exit For
End If
End If
Next htmlInput
发布于 2015-03-25 21:53:33
您可以尝试使用Application.DisplayAlerts函数包装该行,该函数会生成您不想要的显示框;
例如:
If Trim(htmlInput.ID) = "btn" Then
If Trim(htmlInput.Name) = "btnfinal" Then
Application.DisplayAlerts = False
htmlInput.Click
Application.DisplayAlerts = True
.... Further Code
发布于 2016-05-03 05:05:40
我遇到了这个问题,唯一能解决这个问题的方法就是编写一个vb脚本来识别弹出窗口并关闭它……
在此之后,您只需从vba代码中调用它。
https://stackoverflow.com/questions/29249300
复制相似问题