So i am writing some VBA code to step through a website and i keep getting an "Object variable or with block variable not set error" I can usually step through the code without error, which led me to believe it was a timing issue. I loaded this code up with wait statements and still would get that error. Any thoughts? Am i doing something crazy?
Sub Do_Work_Son()
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim plnSelect As HTMLSelectElement 'this selects the plan
Dim adrInput As HTMLInputElement 'this selects the address
Dim dirSelect As HTMLSelectElement 'this selects the distance
Dim strSQL As String
Dim LString As String
Dim LArray() As String
strSQL = "http://avmed.prismisp.com/?tab=doctor"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate strSQL
Do Until .readyState = READYSTATE_COMPLETE: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:5"))
Set doc = IE.document
'Call WaitBrowser(IE)
'-----------------------------
'--Start Page Select Criteria--
'-----------------------------
Set plnSelect = doc.getElementsByClassName("full jqSelectPlan")(0)
plnSelect.selectedIndex = 1
Set adrInput = doc.getElementsByClassName("address-type-ahead enteredText ac_input defaultText")(0)
adrInput.Value = "32258" 'this is where we will link to zip code table
Set dirSelect = doc.getElementsByName("Proximity")(0)
dirSelect.selectedIndex = 0
doc.getElementsByClassName("button large")(0).click 'this submits the initial page
'------------------------------------------------------
'Call WaitBrowser(IE)
Application.Wait (Now + TimeValue("0:00:03"))
Debug.Print (doc.getElementsByClassName("profileDetails")(0).innerText)
LString = doc.getElementsByClassName("profileDetails")(0).innerText
LArray = Split(LString, vbCrLf)
Debug.Print (LArray(0))
Application.Wait (Now + TimeValue("0:00:2"))
Sheet1.Range("A1") = LArray(0)
Sheet1.Range("B1") = LArray(2)
Sheet1.Range("C1") = LArray(3)
Sheet1.Range("D1") = LArray(4)
Sheet1.Range("E1") = LArray(5)
Sheet1.Range("F1") = LArray(6)
End With
End Sub