Internet explorer 在现有网站上执行Visual Basic
我试图弄清楚如何在已经打开的网页上操作表单字段(文本框和按钮),而不必打开Internet Explorer的新实例,也不必首先导航到特定的URL 我目前有以下代码打开google,填写搜索字段并单击google搜索按钮:Internet explorer 在现有网站上执行Visual Basic,internet-explorer,Internet Explorer,我试图弄清楚如何在已经打开的网页上操作表单字段(文本框和按钮),而不必打开Internet Explorer的新实例,也不必首先导航到特定的URL 我目前有以下代码打开google,填写搜索字段并单击google搜索按钮: Sub Main Dim objIE Dim UserN Dim url As String url = "http://www.google.com" Set objIE = CreateObject("Intern
Sub Main
Dim objIE
Dim UserN
Dim url As String
url = "http://www.google.com"
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate url
WaitForLoad (objIE)
' runs the sub "Wait for Load" that waits until the page is fully loaded before continuing the script
MsgBox "It Loaded"
Set UserN = objIE.document.getElementsByName("q")
If Not UserN Is Nothing Then
' fill in first element named "q", assumed to be the login name field
UserN(0).value = "Dragon NaturallySpeaking"
End If
Wait 2
Dim f
Set f = objIE.document.getElementsByName("btnK")
f(0).click
End Sub
Sub WaitForLoad (objIE)
Do While objIE.Busy
Wait .1
Loop
End Sub
我目前的问题是,我希望能够填写搜索字段并单击谷歌搜索按钮,而不必首先导航到www.Google.com。例如,我已经打开浏览器并访问了www.google.com,但现在我想执行填充文本字段并单击按钮的脚本。不幸的是,我找不到这样做的方法。我尝试过使用Set objIE=GetObject(“InternetExplorer.Application”)——而不是CreateObject——并删除objIE.Visible=True和objIE.Navigate url,但这只会返回一个错误