Hello
I have this code that was kindly written for me. I have used it quite often with much success. Yesterday it was running and came back with a Run-time error (see pic 1) I'm confident this error came from the API source (probably from the amount of calls 12,000 total) and not my code. I am however, able to re-start the code directly after, and pull more data until it crashes again.
Here's a briefing of what's happening:
The code goes to the API page in column A and saves the JSON file in the directory in column B with the file name in column C.
The code then loops through all the rows. (Column D isn't relevant for the code, but its where I list all the IDs needed for each page/call.)
What is wondering is two fold. First, can the code be manipulated to restart if this error occurs, and secondly can it pick up where it left off in the loop?
I will attach a couple of pictures and a sample file, along with the code.
Thanks for your time, and input,
Joe
Sub update_game_id()
Dim objWHTTP As Object
Dim strPath As String
Dim arrData() As Byte
Dim lngFreeFile As Long
Dim rangeA As Range
Dim dirpath As String
Dim filepath As String
On Error Resume Next
Set objWHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set objWHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
For Each rangeA In Range("a1", Range("a1").End(xlDown))
strPath = rangeA
dirpath = rangeA.Offset(0, 1)
filepath = dirpath & rangeA.Offset(0, 2)
objWHTTP.Open "GET", strPath, False
objWHTTP.send
arrData = objWHTTP.responseBody
If Len(Dir(dirpath, vbDirectory)) = 0 Then
MkDir (dirpath)
End If
lngFreeFile = FreeFile
Open filepath For Binary Access Write As #lngFreeFile
Put #lngFreeFile, 1, arrData
Close #lngFreeFile
Next rangeA
Set objWHTTP = Nothing
Erase arrData
Beep
MsgBox "Done"
End Sub
Bookmarks