I'm sorry if my request won't be very clear, but I'm not very familiar with the topic.
I'm trying to extract a Json database using VBA and, of course, Microsoft Excel.
My code is (simplified):
Function GetDB(ByRef MYUrl As String) As Integer
'variables declaration here ...
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "GET", MyUrl, False
xmlHttp.setRequestHeader "Content-Type", "application/json"
xmlHttp.send ""
JsonResponse = xmlHttp.responseText
Set sc = CreateObject("ScriptControl"): sc.Language = Script"
Set json = sc.Eval("(" + jsonResponse + ")")
MyRecords = json.totalRecords
End Function
The problem is that in "MyUrl", I set different ”filters" where one has spaces in it. To make it more clear, MyUrl looks like:
MyUrl = "http://domain.xxxx.xxxx.com/pathpart1/pathpart2?DateFrom=20250620&DateTo=20250630&Folder=STRING - STRING&File=MyFile"
So the problem is about the spaces in the "STRING - STRING" part of MyUrl. Removing this part, the code works, but it does not apply the filter I would need. How can I solve?
I would like to understand how to "replace" the spaces " " in MyUrl with a character that can be read by the Object "MSXML2.ServerXMLHTTP". The rest of the Url is fine and doesn't need to be reviewed (but in its anonymized version could be imprecise, I understand). In fact, if I remove the part "Folder=STRING - STRING" the code runs smoothly (but I would need also this additional filter to get data from the Folder I want).
I tried to replace the space " " with "%20", but it does not work.
Thank you for your help
debug.print MyUrland then copy/paste the result into a browser.STRING - STRING? Is it possible the "spaces" are not spaces but some other character? What exactly happens when you include the original string? You just don't get the expected results, or something else? Can you successfully target a folder which has no spaces in its name?Eval()is not running in a sandboxed environment as it would if you were doing the equivalent thing in a web browser environment.