Search code examples
excelhttpexcel-udfvba

VBA call webpage without opening browser or returning data


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


Solution

  • 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