这是代码块的中间部分,我在其中添加了一个循环来访问每个单元格并将其值传递给变量。
我省略了我创建IE对象,访问网站等的代码部分,因为它似乎工作正常。循环是我不确定的。
我需要改变什么?
Dim name As String
Dim address As String
Dim city As String
Dim state As String
Dim zip As String
Dim phone As String
Range.Row = i
For i = 2 To 626
name = Cells(A, i).Value
address = Cells(B, i).Value
city = Cells(C, i).Value
state = Cells(D, i).Value
zip = Cells(E, i).Value
phone = Cells(F, i).Value
IE.Document.all("butAdd").Click
If IE.Document.Title = " PestPac - Maintain Notification Locations" Then
IE.Document.getElementById("Name").Value = name
IE.Document.getElementById("Address").Value = address
IE.Document.getElementById("City").Value = city
IE.Document.getElementById("State").Value = state
IE.Document.getElementById("Zip").Value = zip
IE.Document.getElementById("Phone").Value = phone
IE.Document.getElementById("Distance").Value = "0.1"
IE.Document.all("butAdd").Click
Exit For
Next i
End Sub
答案 0 :(得分:0)
您需要在End If
之后的If
语句末尾添加Exit for
语句。如果您希望文档标题是其他内容,则还可以添加Else
。