我有一个Excel文档。它创建一个Internet Explorer实例并导航到URL。
我正在使用duckduckgo进行测试
我希望能够在vba中响应在网站上单击的按钮。
[html.querySelector("#search_button_homepage")
找到输入元素,如何检测onclick事件并运行一些vba代码?
我的目标是获取用户在Web表单中键入的数据,并将其放入excel文档中。
Private Sub cmdTest_Click()
Dim IE As InternetExplorer, html As Object
Set IE = New InternetExplorer
Dim link As String
link = "http://www.duckduckgo.com/"
With IE
.Visible = True
.navigate link
While .Busy = True Or .readyState < 4
DoEvents
Wend
Set html = .document
html.querySelector("#search_button_homepage")
' Respond to html.querySelector("#search_button_homepage") being clicked.
End With
ShowWindow IE.hwnd, SW_SHOWMAXIMIZED
End Sub
尝试此部分
Set html = .document
html.queryselector("#search_form_input_homepage").Value = "Excel VBA"
html.queryselector("#search_button_homepage").Click