“点击"使用VBA的javascript按钮 [英] "Click" a javascript button with VBA
问题描述
无休止的谷歌搜索和许多解决方案似乎无济于事.我不断收到无穷无尽的各种错误,除非找到让代码等待四秒钟(而我用鼠标手动单击它)的代码,否则找不到单击该按钮的优雅方法.
endless googling and lots of solutions haven't seemed to help. I keep getting endless errors of different kinds, and just can't find an elegant way of clicking this button unless I get the code to wait for four seconds while I click it manually with my mouse.
它可以在其他按钮上使用,但是如果这里的问题是嵌套的doPostBack和其中的许多''(从"代替),那么我在工作吗?
It works on other buttons, but I'm working if the problem here is the nested doPostBack and the many '' (substituted from "") in it?
下面的代码(我已经删除了不相关的部分)
Code below (I've trimmed out irrelevant sections)
VBA代码:
Sub IE_Clicks()
Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Set shellWins = New ShellWindows
If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
IE.Visible = True
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = True
End If
IE.Navigate ("[URL]")
Do While (IE.Busy Or IE.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
Call IE.document.parentWindow.execScript("WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$cphMain$btnAddTab', '', true, '', '', false, false))", "JavaScript")
Set IE = Nothing
End Sub
HTML代码:
<input type="submit" name="ctl00$cphMain$btnAddTab" value="Add New" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$btnAddTab", "", true, "", "", false, false))" id="ctl00_cphMain_btnAddTab" class="ActionButton">
JavaScript:
JavaScript:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
使我能够单击此按钮的东西真是太神奇了.
Something that would enable me to click this button would be amazing.
推荐答案
这应该有效:
IE.document.getElementById("ctl00_cphMain_btnAddTab").Click
这篇关于“点击"使用VBA的javascript按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!