1

現在のコードは次のとおりです。

Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "https://www.website.com/"
Application.StatusBar = "https://www.website.com/ is loading. Please wait..."
Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
    Loop
Application.StatusBar = "Search form submission. Please wait..."

私が経験している問題は、「https://www.website.com/」がときどきロードに失敗することです (これは、繰り返しアクセスしているためだと思います)。その結果、コードがこのループを超えて移動することはありません。

Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
    Loop

私の意見では、論理的な解決策は、特定の時間制限 (30 秒?) に達した後に IE を強制終了し、プロセス全体を再起動することです。このソリューションをコーディングする方法、および/またはより効果的なソリューションをまとめてコーディングする方法についてアドバイスしてください。よろしくお願いします!それが重要な場合は、IE10を使用しています。

また、関連する関連情報が含まれているリンクを見つけました: http://www.ozgrid.com/forum/showthread.php?t=161094

4

3 に答える 3

5

コードを変更して読むことができます

Sub LoadWebsite()
Dim iSecondCounter As Integer
Static iAttempts As Integer

iAttempts = iAttempts + 1

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "https://www.website.com/"
Application.StatusBar = "https://www.website.com/ is loading. Please wait..."

iSecondCounter = 0
Do While ie.Busy And iSecondCounter < 30
    Application.Wait DateAdd("s", 1, Now)
    iSecondCounter = iSecondCounter + 1
Loop
If iSecondCounter = 30 Then
    ie.Quit
    If iAttempts <= 3 Then Call LoadWebsite
End If

Set ie = Nothing
End Sub
于 2013-08-16T03:07:02.003 に答える
0

OK、あなたは HTML 要素のコレクションを取得することについて新しい質問をしているようですので、新しい回答として投稿します。オブジェクト エラーが発生する理由は、objCollection を正しいオブジェクトにディメンション化していないためと思われます。これを行うために元の回答のコードを変更し、スニペットのようにコレクションを設定しました。このコードを使用するには、Microsoft HTML Object Library への参照を含める必要がありました。

このコードは、サブを終了する前に要素コレクションを破棄することに注意してください。おそらく、それで何かをしたいと思うでしょう。

Sub LoadWebsite()
Dim iSecondCounter As Integer
Static iAttempts As Integer
Dim objCollection As IHTMLElementCollection
iAttempts = iAttempts + 1

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "https://www.website.com/"
Application.StatusBar = "https://www.website.com/ is loading. Please wait..."

iSecondCounter = 0
Do While ie.Busy And iSecondCounter < 30
    Application.Wait DateAdd("s", 1, Now)
    iSecondCounter = iSecondCounter + 1
Loop
If iSecondCounter = 30 Then
    ie.Quit
    If iAttempts <= 3 Then Call LoadWebsite
End If


Set objCollection = (ie.Document.getElementsByTagName("INPUT"))

Cleanup:

Set ie = Nothing
Set objCollection = Nothing

End Sub
于 2013-08-16T22:44:11.493 に答える