The following code was originally running without lines 40 through 80 and frequently threw an unknown error at line 30. Moments later the code would continue successfully when run in the Debug mode. Lines 40 through 80 were added and appear to have resolved the problem however I am concerned that I may be approaching the problem from the wrong direction. Any comments will be most welcome.
Function GetQueryData(strStartURL As String, Abort As Boolean, _
Optional strEndPage As String = vbNullString) As String
' Jefferson F. Scher 05/04/2006
' Uses IE DOM to open web page and retrieve the contents _
of one HTML table cell into a string
' Requires adding the following under Tools>References:
' Microsoft HTML Object Library
' Microsoft Internet Controls
Dim PostURL As String
Dim MainPost As String
Dim Board As String
Dim ArrCol As Long
Dim ArrRow As Long
10 GetQueryData = "Complete"
'Create browser object references and open an IE window
Dim ieNew As New InternetExplorer
LoadPage:
20 On Error Resume Next
30 With ieNew
40 If Err Then
50 On Error GoTo 0
60 Sleep 500
70 GoTo LoadPage
80 End If
90 .Visible = True 'show window
100 .navigate strStartURL 'open page
110 While Not .readyState = READYSTATE_COMPLETE
120 Sleep 500 'wait 1/2 sec before trying again
130 Wend
140 If strEndPage vbNullString Then 'check for ending page
Dim intQueryPos As Integer, strCurrentPage As String
150 Do
160 intQueryPos = InStr(1, .LocationURL, "?")
170 If intQueryPos > 0 Then
180 strCurrentPage = Left(.LocationURL, intQueryPos - 1)
190 If StrComp(strCurrentPage, strEndPage, vbTextCompare) = 0 Then Exit Do
200 End If
210 Sleep 500 'wait 1/2 sec before trying again
220 Loop
' Now wait for page to finish loading
230 While Not .readyState = READYSTATE_COMPLETE
240 Sleep 500 'wait 1/2 sec before trying again
250 Wend
260 End If
270 End With