My Excel VBA-code below calls a local server on my computer although sometimes it stops and gives the following error :
Run-time error '2147012894 (80072ee2)': The operation timed out.
This is the Excel VBA code:
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", myurl, False
http.send
The error occurs at line http.send.
I am not sure why the error occurs. I have 4 Excel instances running at once. All calling the local server once a minute.
I would like to solve the issue in order to keep the code running after the error.
I can find several posts about MSXML2.ServerXMLHTTP.6.0 although since I am not familiair with it I do not succeed to implement a solution.
Thanks a lot!
UPDATE 1:
I have modified my code in this way:
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", myurl, False, "", ""
http.send
If http.readyState = 4 Then
'Debug.Print http.responseText
Else: Debug.Print "xmlhttp.ReadyState =" & http.readyState
End If
'*** process received JSON-response in code below
Set JSON = ParseJson(http.responseText)
Although if I turn off the local server, the code still stops at line http.send
I have modified the code in this way:
UPDATE 2:
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
minute_to_wait_api = 50
flag_api = True
starttime_api = Timer
http.Open "GET", myurl, False, "", ""
http.send
Do
DoEvents
DoEvents
endtime_api = Timer
endtime_api = Round(endtime_api - starttime_api, 0)
If endtime_api >= minute_to_wait_api Then
flag_api = False
Exit Do
End If
Loop While http.readyState <> 4
If flag_api = False Then
Debug.Print "API Taking too long to respond"
Exit Sub
End If
If http.Status <> 200 Then
Debug.Print "http_error: " & http.Status
Exit Sub
End If