How do I issue an HTTP GET from Excel VBA for Mac

前端 未结 3 1130
庸人自扰
庸人自扰 2020-11-29 04:28

I need to issue an HTTP Get with a query string to a web service from Excel for Mac 2011. I\'ve seen the answers for using QueryTables (How can I send an HTTP POST request

3条回答
  •  萌比男神i
    2020-11-29 04:52

    Another option (update accordingly if your curl is not located in /opt/local/bin/curl):

    VBA:

    Public Function getUrlContents(url) As String
        Dim command As String
        command = "do shell script ""/path_to/getUrl.sh " + url + """"
        getUrlContents = VBA.MacScript(command)
    End Function
    

    /path_to/getUrl.sh:

    #!/bin/sh
    
    if [ -z "$1" ]
      then
        echo "missing url argument"
    else
        /opt/local/bin/curl "$1"
    fi
    

    Note that you will have to ensure that getUrl.sh is executable:

    chmod u+x getUrl.sh
    

提交回复
热议问题