HTTP GET request with Excel 2019 Mac VBA

siamond

New Member
Joined
Mar 19, 2019
Messages
42
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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Yes, I did, using a slightly optimized variation of the code above. I'd be happy to bypass curl and have proper access to response headers, but it does work ok for my needs.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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
Back
Top