VBA call webpage without opening browser or returning data

3.3k Views Asked by At

I am trying to create an excel UDF that calls a web page that runs scripts which take values from parameters in the URL. EG: "http://example.com.com/script.php?variable1=123&variable2=456&etc=etc"

I have used this after much googling and trying things from other stackoverflow answers. yes it creates a udf, yes you can enter a cell value in the udf, but no it does not call the URL (visits tracking on the URL says it has not been called).

Function callurl(urltocall As String) As String
Dim urlText As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", urltocall, False
.send
urlText = .responseText
End With
End Function

I do not need it to return any data, just to call the URL to run the script. The point of doing this is to take variables from excel and use them as parameters in the URL which will run a script and update a web SQL database.

The actual result was nothing (blank cell in excel, no visit to webpage).

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

The function doesn't return any result. Here's correct code:

Function callurl(urltocall As String) As String
    Dim urlText As String
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", urltocall, False
        .Send
        urlText = .responseText
    End With
    callurl = urltext
End Function
0
On

Later versions of Excel have a formula that does this without needing a UDF.

The formula is: =WEBSERVICE("yoururlhere.com")

See this article on office.com for additional info.