我正在尝试输入单元格C4
的值,该值是从输入框中获取的,该输入框将值分配给单元格,在第一页提交后输入搜索框但我无法我一直收到错误438.输入框后我的代码有问题吗?
有没有办法可以让代码等到单元格C4
分配输入框中的值,然后继续填写第2页?
此外,我正在使用Internet Explorer 11,如果我想使用已打开的浏览器进行操作,我的objItem.FullName Like
应该是什么?
Option Explicit
Const word1 As String = "C2"
Const word2 As String = "C3"
Const word3 As String = "C4"
Public Sub Test()
Dim objWindow As Object
Dim objIEApp As Object
Dim objShell As Object
Dim objItem As Object
Dim wordthree As String
On Error GoTo Fin
Set objShell = CreateObject("Shell.Application")
Set objWindow = objShell.Windows()
For Each objItem In objWindow
If LCase(objItem.FullName Like "*iexplore*") Then
Set objIEApp = objItem
End If
Next objItem
If objIEApp Is Nothing Then
Set objIEApp = CreateObject("InternetExplorer.Application")
objIEApp.Visible = True
End If
With objIEApp
.Visible = True
.Navigate "google.com"
While Not .ReadyState = 4
DoEvents
Wend
.Document.all.q.Value = Range(word1).Value
'.Document.all.q.Value = Range(word2).Value
.Document.forms(0).submit
End With
3word = InputBox("Enter 3rd word: ")
Range("C4").Value = wordthree
With objIEApp
.Visible = True
While Not .ReadyState = 4
DoEvents
Wend
.Document.all.q.Value = Range(word3).Value
.Document.forms(0).submit
End With
Fin:
If Err.Number <> 0 Then MsgBox "Error: " & _
Err.Number & " " & Err.Description
Set objWindow = Nothing
Set objShell = Nothing
End Sub
答案 0 :(得分:0)
我在这里可以看到的第一件事是你试图用数字命名你的变量。在VB世界(包括VBA,VB.Net等)中,这是无效的&amp;你的代码不起作用。
有关变量命名规则的详细信息,请参阅https://msdn.microsoft.com/en-us/library/office/gg264773.aspx。
<强>更新强>
接下来的事情&amp;您收到错误的原因是,您需要在调用错误处理例程代码之前包含一个退出方法的调用。现在,通过添加“exit sub”语句,我上面的代码正常工作。
.Document.all.q.Value = Range(word3).Value
.Document.forms(0).submit
End With
**Exit Sub**
Fin:
If Err.Number <> 0 Then MsgBox "Error: " & _