VBA发送GET、POST请求

原创文章,欢迎转载:http://miao.blog/article/vba-http-request

下边是从腾讯的一个时间API取数据的示例:

Public Function getTimeFromAPI() As String
    On Error GoTo ERR_HANDLING

    Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP")
    url = "http://cgi.im.qq.com/cgi-bin/cgi_svrtime"
    HttpReq.Open "get", url, False
    HttpReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    HttpReq.send
    
    getTimeFromAPI = HttpReq.responseText
    Exit Function
ERR_HANDLING:
    getTimeFromAPI = Date
End Function
推荐阅读
获取Excel的AddIn里边的Sheet对象
评论