【发布时间】:2019-09-03 06:47:26
【问题描述】:
我正在自动执行搜索过程并下载结果。
我的代码运行一行,我想为1st column 中的每个填充单元格循环相同。我尝试了下面的代码,但抛出了一个错误
Private Sub CommandButton1_Click()
Dim i As Integer
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLAs As MSHTML.IHTMLElementCollection
Dim HTMLA As MSHTML.IHTMLElement
Dim Aone As Range
Dim Bone As Range
Dim Cone As Range
Dim SearchButton As Object
Dim Results As Variant
For i = 1 To 3
IE.Visible = False
IE.navigate "https://www.twinword.com/api/text-similarity.php"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Set Aone = Range("Ai")
Set Bone = Range("Bi")
Set Cone = Range("Ci")
Set HTMLInput = HTMLDoc.getElementById("demoInput1")
HTMLInput.Value = Aone.Value
Set HTMLInput = HTMLDoc.getElementById("demoInput2")
HTMLInput.Value = Bone.Value
Set SearchButton = HTMLDoc.getElementById("demoButton")
'click on the first (and presumably only) object in the collection
SearchButton.Click
Application.Wait (Now + TimeValue("0:00:02")) '2sec
Results = HTMLDoc.getElementById("demoBox").innerText
Range("Ci").Value = Results
Next i
End Sub
只想为Column A中的所有单元格运行所需的循环
【问题讨论】: