按照this post我已經修復了對象檢查器。有時代碼可以正常運行10個條目,使它們全部正確,有時它會運行五次。有時會得到錯誤的條目。什麼是間歇性地打破我的短塊VBA?
它總是傾向於失敗的元素獲取innertertext。當Y/N結果錯誤時,我根本不知道是什麼原因造成的。
請幫忙!這讓我很生氣。我錯誤地檢查了每個階段。
Sub LetsAutomateIE()
Dim barcode As String
Dim rowe As Integer
Dim document As HTMLDocument
Dim Element As HTMLDivElement
Dim text As String
Dim pos As Integer
Set ie = CreateObject("InternetExplorer.Application")
rowe = 2
While Not IsEmpty(Cells(rowe, 2))
barcode = Cells(rowe, "B").Value
pos = 0
text = ""
Set document = Nothing
With ie
.Visible = False
.navigate2 "https://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=" & barcode
Do Until ie.readyState = 4
Loop
End With
Set document = ie.document
If IsObject(document.getElementById("result_0")) = False Then GoTo Here
text = document.getElementById("result_0").innerText
If InStr(text, "STEELBOOK") Or InStr(text, "Steelbook") Or InStr(text, "Steel book") <> 0 Then pos = 1
If pos <> 0 Then Cells(rowe, 4) = "Y" Else Cells(rowe, 4) = "N"
Here:
rowe = rowe + 1
Wend
Set ie = Nothing
End Sub
下面是我正在使用的示例條碼選擇。我從來沒有設法成功通過這些。
5030305517076
5030305517816
5060223767925
5060223767949
5060223767956
5060223767970
5060223767994
8717418358563
8717418365851
太感謝你了,
山姆
將'DoEvents'放入等待循環中嗎? – GSerg