使用VBA在网站按钮上调用onclick JS事件
我正在使用VBA与IE中的网站进行交互 作为这项工作的一部分,我需要单击那里的一个按钮,但是一个简单的使用VBA在网站按钮上调用onclick JS事件,vba,excel,internet-explorer,onclick,Vba,Excel,Internet Explorer,Onclick,我正在使用VBA与IE中的网站进行交互 作为这项工作的一部分,我需要单击那里的一个按钮,但是一个简单的。单击不起作用,因为我需要触发此按钮后面的JS onclick事件 这里有人能告诉我如何实现这一点,或者通过模拟点击并触发事件,或者直接调用JS事件 这应该发生在下面的VBA代码之后 我的VBA代码: Dim IE As Object Dim MyURL As String Dim varResults As New DataObject varResults.SetText TxtSql.T
。单击不起作用,因为我需要触发此按钮后面的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
javascript:document.forms.jobProfileForm.action='https://mySecondUrl';document.forms.jobProfileForm.submit()
<input class="normalbttn" id="editProfileBttn" value="Edit Profile" onclick="theAboveJS" type="button"></input>
按钮后面的onclick JS事件:
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
javascript:document.forms.jobProfileForm.action='https://mySecondUrl';document.forms.jobProfileForm.submit()
<input class="normalbttn" id="editProfileBttn" value="Edit Profile" onclick="theAboveJS" type="button"></input>
按钮的HTML:
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
javascript:document.forms.jobProfileForm.action='https://mySecondUrl';document.forms.jobProfileForm.submit()
<input class="normalbttn" id="editProfileBttn" value="Edit Profile" onclick="theAboveJS" type="button"></input>
试试这个:
IE.Document.getelementbyid(“editProfileBttn”).fireevent(“onclick”)
尝试以下操作:
IE.Document.getelementbyid(“editProfileBttn”).fireevent(“onclick”)
谢谢,斯科特!我试过了,但没什么不同-它不会触发按钮/事件,也不会加载带有文本区域的页面。谢谢,斯科特!我尝试了这个方法,但没有区别——它不会触发按钮/事件,也不会加载带有文本区域的页面。