Runtime error 91 on website login

A

ajbarilla

I have code that copies data from a website into excel. Since its a
login site, I can get a webquery to work correct. The following code
works about 90% of the time but 10% of the time I get an "object
variable or with block variable not set - runtime error 91" error on
ipf.value=username line. Im not sure why i am getting this error.
Any help would be appreciated.

Dim username As String
Dim password As String
Dim ie as object
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.Navigate "https://mywebsite"
Do Until Not .busy
DoEvents
Loop

username = ActiveSheet.Range("z1").Value
Debug.Print username
password = ActiveSheet.Range("z2").Value
Debug.Print password

Set ipf = ie.document.all.Item("s10_")
ipf.Value = username <--------ERROR HERE
Set ipf = ie.document.all.Item("s12_")
ipf.Value = password
Set ipf = ie.document.all.Item("s16_")
ipf.Click
Do Until Not .busy
DoEvents
Loop

End With
 
T

Tim

Looks as though for some reason there is no "ipf" input element in the
document.
Try adding some error checking to catch this. Eg:

Set ipf = ie.document.all.Item("s10_")

If ipf is nothing then
Msgbox "Input 's10_' not found!"
Exit sub
Else
ipf.Value = username
End If


Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top