Hi everyone,

I have a macro that runs through a column of URLs and extract the same data from each URL. The problem is that occasionally the macro errors with "Run-time error 5: Invalid procedure call or argument". It errors at the line: "RXLocation = InStr(URLLocation ..." When I manually visit the URL in IE it opens fine. Any ideas what is causing this problem?

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = False

Dim r As Integer
For r = 0 to 10000

IE.navigate ("http://www.racingvictoria.net.au/Racing/fullform.aspx?meet_code=" & Cells(3 + r, 3))

Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE

'Extract Race Code

Dim Doc As HTMLDocument
Set Doc = IE.document
Dim HTMLSource As String
HTMLSource = Doc.Body.innerHTML

Dim URLLocation As Long
URLLocation = InStr(1, HTMLSource, "Racing/fullform.aspx?meet_code=" & Cells(3 + r, 3) & "&race_code=")
Dim RXLocation As Long
RXLocation = InStr(URLLocation, HTMLSource, Chr(34) & Chr(62) & "R")
Dim RaceCodeStart As Long
RaceCodeStart = URLLocation + Len(Cells(3 + r, 3)) + 46
Dim RaceCode As Long
RaceCode = Mid(HTMLSource, RaceCodeStart, RXLocation - RaceCodeStart)

Cells(3 + r, 4) = RaceCode

Next r
Cheers, Rob