【发布时间】:2017-02-03 16:15:32
【问题描述】:
我正在使用 VBA 与 IE 中的网站进行交互。
作为其中的一部分,我需要在那里单击一个按钮,但一个简单的.Click 不起作用,因为我需要触发此按钮后面的 JS onclick 事件。
这里有人可以告诉我如何通过模拟点击并触发事件或直接调用 JS 事件来实现这一点吗?
这应该发生在下面的 VBA 代码之后。
我的 VBA 代码:
Dim IE As Object
Dim MyURL As String
Dim varResults As New DataObject
varResults.SetText TxtSql.Text
varResults.PutInClipboard
Unload FrmResults
Set IE = CreateObject("InternetExplorer.Application")
MyURL = "https://myFirstUrl"
IE.Navigate MyURL
IE.Visible = True
While IE.busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02")) ' to allow time for loading the page
按钮后面的onclick JS事件:
javascript:document.forms.jobProfileForm.action='https://mySecondUrl';document.forms.jobProfileForm.submit()
按钮的 HTML:
<input class="normalbttn" id="editProfileBttn" value="Edit Profile" onclick="theAboveJS" type="button"></input>
【问题讨论】:
标签: vba excel internet-explorer onclick