Hi All,
I have looked for a day and a 1/2 and googled, read and experimented far and wide but am unable to sovle this problem.
I have a VBA routine in Excel that automates logging into a website as follows :
<code>
Sub Mysub()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
base_url = "https://www.somesite.com/"
ie.navigate base_url & "displayLogon.do?o=p&client=somename"
While ie.Busy
DoEvents
Wend
ie.document.getElementById("loginID").value = "my Login"
ie.document.getElementById("accessCode").value = "my Password"
ie.document.forms(0).submit
'trying early binding to see if that helps - same problem
'Dim ieObj As HTMLInputElement
'With ie
' Set ieObj = .document.getElementById("loginID")
' ieObj.Value = "my Login"
' Set ieObj = .document.getElementById("accessCode")
' ieObj.Value = "my Password"
' .document.Forms(0).submit
'End With
While ie.Busy
DoEvents
Wend
Exit Sub
</code>
The code sometimes works perfectly, and sometimes fails with a Run-Time Error 91 "Object variable or With Block variable not set".
It's horrible because it's intermittent.
If you run something like :
<code>
Sub tester()
For i = 1 To 6
Call Mysub
Next i
End Sub
</code>
..then it will for example work the first 2 times and then on the 3rd time it will return the 91 after having opened a new instance of IE and having navigated to the first window.
That is, the Run-time Error 91 occurs somewhere in the ie.document.getElementById area of the code.
Even more frustrating, if you set breakpoints and single-step it the code will ALWAYS work - it appears that either the time-delay or the invocation of the Debugger itself somehow causes this error not to occur .
Any and all help greatly appreciated !
Thanks,
Warren.
I have looked for a day and a 1/2 and googled, read and experimented far and wide but am unable to sovle this problem.
I have a VBA routine in Excel that automates logging into a website as follows :
<code>
Sub Mysub()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
base_url = "https://www.somesite.com/"
ie.navigate base_url & "displayLogon.do?o=p&client=somename"
While ie.Busy
DoEvents
Wend
ie.document.getElementById("loginID").value = "my Login"
ie.document.getElementById("accessCode").value = "my Password"
ie.document.forms(0).submit
'trying early binding to see if that helps - same problem
'Dim ieObj As HTMLInputElement
'With ie
' Set ieObj = .document.getElementById("loginID")
' ieObj.Value = "my Login"
' Set ieObj = .document.getElementById("accessCode")
' ieObj.Value = "my Password"
' .document.Forms(0).submit
'End With
While ie.Busy
DoEvents
Wend
Exit Sub
</code>
The code sometimes works perfectly, and sometimes fails with a Run-Time Error 91 "Object variable or With Block variable not set".
It's horrible because it's intermittent.
If you run something like :
<code>
Sub tester()
For i = 1 To 6
Call Mysub
Next i
End Sub
</code>
..then it will for example work the first 2 times and then on the 3rd time it will return the 91 after having opened a new instance of IE and having navigated to the first window.
That is, the Run-time Error 91 occurs somewhere in the ie.document.getElementById area of the code.
Even more frustrating, if you set breakpoints and single-step it the code will ALWAYS work - it appears that either the time-delay or the invocation of the Debugger itself somehow causes this error not to occur .
Any and all help greatly appreciated !
Thanks,
Warren.