Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl URL and post results in Excel cell?

Tags:

json

curl

excel

vba

I have 200 rows in an Excel sheet that I would like to include in a curl (or any kind of HTTP get) and see the results in a second column.

**Column A**
123
456
789
012
...

I have tried using the Excel option to get data from an external web page but it doesn't appear to work for multiple row on the same sheet. Is there a way for me to append the value in Column A to a static URL (ie:http://testurl.net/page.php?ID=[Column A]) so that the result of the page is shown in Column B? I know the response from the URL will be a rest response that will display only a couple words.

Thank you

like image 777
AAA Avatar asked Oct 31 '14 19:10

AAA


People also ask

Can Excel connect to a REST API?

You can use the Excel REST API in Microsoft Graph to extend the value of your Excel data, calculations, reporting, and dashboards.


2 Answers

you can do this by using a http request object:

Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText

If you are behind a proxy you can use something like this:

Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.setProxy HTTPREQUEST_PROXYSETTING_PROXY, "http://proxy.intern:8080"
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText

and if you want to use POST (instead of the GET method) to pass some values to the webserver, you can try this:

Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "POST", "http://www.cboden.de/misc/posttest.php"
oRequest.SetRequestHeader "Content-Typ", "application/x-www-form-urlencoded"
oRequest.Send "var1=123&anothervar=test"
MsgBox oRequest.ResponseText

if you put it into a function then you can use it in you worksheet:

Function getCustomHyperlink(ByVal pURL As String) As String
    Dim oRequest As Object
    Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    oRequest.Open "GET", pURL
    oRequest.Send
    getCustomHyperlink = oRequest.ResponseText
End Function

within the worksheet you can then say for example:

=getCustomHyperlink("https://www.google.com/search?q=" & A1 )

if your search value is in A1

like image 59
cboden Avatar answered Oct 07 '22 01:10

cboden


You can also use the WEBSERVICE(url)

enter image description here

like image 32
rupweb Avatar answered Oct 07 '22 01:10

rupweb