Hi there, I have developed various scripts with Google Sheet to perform HTTP GET queries, retrieve JSON content (e.g. historical financial data) and programmatically parse the content to return an array of data to a spreadsheet. I programmed all the parsing myself, starting from the HTTP Response stored in a large string. I didn't use any JSON parsing library.
Now I am exploring switching to Excel VBA, which I never used before. I have Office 2019, running on a MacBook, with no desire to upgrade to any of those subscription-based new versions of Office. So.. no 'power query', no Microsoft XML library, etc.
I spent several hours researching the Web and call me stupid, but all I can find are VBA scripts like the one quoted below, making using of 'query tables'. It's a start, but it is NOT what I'd like to do though:
- I need a way to set HTTP header fields (e.g. referer)
- I don't want any pre-canned table parsing or whatever, just give me the full HTTP text response (which will include in turn the JSON content) to parse...
- And I don't want the HTTP Response to go in the spreadsheet itself, I want it in a string, then process it before returning the data of interest
Help, please? I mean, if this query table mechanism works (yes, it does!), there has to a lower-level API I can use? Thanks in advance...
=============================
Function JMWEB(p1, p2)
Dim webQuery As String
webQuery = "URL;Currency Converter | Foreign Exchange Rates | OANDA" & p1 & "&to=" & p2 & "&amount=1"
With ActiveSheet.QueryTables.Add(Connection:=webQuery, Destination:=Range("A4"))
.RefreshStyle = xlOverwriteCells
.SaveData = True
.Refresh
End With
End Function
Now I am exploring switching to Excel VBA, which I never used before. I have Office 2019, running on a MacBook, with no desire to upgrade to any of those subscription-based new versions of Office. So.. no 'power query', no Microsoft XML library, etc.
I spent several hours researching the Web and call me stupid, but all I can find are VBA scripts like the one quoted below, making using of 'query tables'. It's a start, but it is NOT what I'd like to do though:
- I need a way to set HTTP header fields (e.g. referer)
- I don't want any pre-canned table parsing or whatever, just give me the full HTTP text response (which will include in turn the JSON content) to parse...
- And I don't want the HTTP Response to go in the spreadsheet itself, I want it in a string, then process it before returning the data of interest
Help, please? I mean, if this query table mechanism works (yes, it does!), there has to a lower-level API I can use? Thanks in advance...
=============================
Function JMWEB(p1, p2)
Dim webQuery As String
webQuery = "URL;Currency Converter | Foreign Exchange Rates | OANDA" & p1 & "&to=" & p2 & "&amount=1"
With ActiveSheet.QueryTables.Add(Connection:=webQuery, Destination:=Range("A4"))
.RefreshStyle = xlOverwriteCells
.SaveData = True
.Refresh
End With
End Function