Http request for an array

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I am struggling to make a http request for each item of an array in VBA. When I make the request for a single object there is no problem:

VBA Code:
Dim xml_obj As MSXML2.XMLHTTP60
Set xml_obj = New MSXML2.XMLHTTP60

xml_obj.Open bstrMethod:="GET", bstrURL:=url1
xml_obj.send

But when I try and use the request method for each item in an array I get the error: '-2147024809 (80070057)'.
I can't find anything useful online for the error code.
The code below is throwing the error.

VBA Code:
Dim url1(1 To 5) As String
Dim xml_obj As MSXML2.XMLHTTP60
Set xml_obj = New MSXML2.XMLHTTP60

For i = 1 To UBound(url1)
    xml_obj.Open bstrMethod:="GET", bstrURL:=url1(i) ' error thrown on this line
    xml_obj.send
Next i

I have tested the url1 string for each item in the array before the http request and these are valid strings for the request, so I believe the problem is my code for making the multiple requests.

I am unsure if I need to set an array for the xml_obj. Can anyone help please?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,180
Office Version
  1. 365
Platform
  1. Windows
I see no data in the array. I guess you can do i=1 to 1 and see if the first element does what you want.

Set the 3rd input to False for ASYNC.
VBA Code:
'xml_obj.Open bstrMethod:="GET", bstrURL:=url1(i) ' error thrown on this line
xml_obj.Open "GET", url1(i), False
 

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I see no data in the array. I guess you can do i=1 to 1 and see if the first element does what you want.

Set the 3rd input to False for ASYNC.
VBA Code:
'xml_obj.Open bstrMethod:="GET", bstrURL:=url1(i) ' error thrown on this line
xml_obj.Open "GET", url1(i), False
Hi Kenneth, what does setting the third input to asynchronous do?
 

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,180
Office Version
  1. 365
Platform
  1. Windows
I put it at False. We usually want one process to end before starting another. I guess you can try True to see if that is the better route.
of or requiring a form of computer control timing protocol in which a specific operation begins upon receipt of an indication (signal) that the preceding operation has been completed.
 

Forum statistics

Threads
1,141,314
Messages
5,705,689
Members
421,406
Latest member
kluna90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top