マクロはうまく機能していますが、ループを 100 回実行する必要があり、2 回目の実行後には
Run-time error '-2147417848 (80010108)':
Automation error
The object invoked has disconnected from its clients.
次のオプションを試しました。
Application.CalculateFullRebuild
'ActiveSheet.EnableCalculation = False
'ActiveSheet.EnableCalculation = True
'Application.Calculation = xlCalculationManual
'Application.Calculation = xlCalculationAutomatic
'Application.Wait Time + TimeSerial(0, 0, 1)
'ActiveSheet.Calculate
それでも、それらはすべて 2 回ループし、3 回目には上記のエラーが発生します。以下は私のコードです。
Private Sub Populate_Click()
Dim i As Long
Dim a As Long
Dim x As Long
Dim b As Long
Dim IE As Object
Dim objElement As Object
Dim objElementA As Object
Dim objCollection As Object
Dim objCollectionA As Object
x = 0
While x < 101
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "website" 'make sure you've logged into the page
Do
DoEvents
Loop Until IE.READYSTATE = 3
Do
DoEvents
Loop Until IE.READYSTATE = 4
Application.CalculateFullRebuild
'ActiveSheet.EnableCalculation = False
'ActiveSheet.EnableCalculation = True
'Application.Calculation = xlCalculationManual
'Application.Calculation = xlCalculationAutomatic
'Application.Wait Time + TimeSerial(0, 0, 1)
'ActiveSheet.Calculate
Call IE.document.getelementbyid("name").SetAttribute("value", ActiveSheet.Range("b2").Value)
Call IE.document.getelementbyid("aw_login").SetAttribute("value", ActiveSheet.Range("a2").Value)
Set objCollection = IE.document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).Type = "button" And _
objCollection(i).Value = "Prefill" Then
Set objElement = objCollection(i)
End If
i = i + 1
Wend
objElement.Click
Application.Wait Time + TimeSerial(0, 0, 2)
Set objCollectionA = IE.document.getElementsByTagName("input")
a = 0
While a < objCollectionA.Length
If objCollectionA(a).Type = "submit" And _
objCollectionA(a).Value = "OK" Then
Set objElementA = objCollectionA(a)
End If
a = a + 1
Wend
objElementA.Click
Do
DoEvents
Loop Until IE.READYSTATE = 3
Do
DoEvents
Loop Until IE.READYSTATE = 4
IE.Quit
x = x + 1
Wend
End Sub