什么VBA代码是需要从Excel电子表格执行HTTP POST?
Answer 1:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://www.somedomain.com"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send("")
或者,通过HTTP更大的控制要求,你可以使用WinHttp.WinHttpRequest.5.1代替MSXML2.ServerXMLHTTP 。
Answer 2:
如果你需要它在Mac和Windows的工作,你可以使用QueryTables:
With ActiveSheet.QueryTables.Add(Connection:="URL;http://carbon.brighterplanet.com/flights.txt", Destination:=Range("A2"))
.PostText = "origin_airport=MSN&destination_airport=ORD"
.RefreshStyle = xlOverwriteCells
.SaveData = True
.Refresh
End With
笔记:
至于输出...我不知道这是否是可能的结果返回给调用VBA函数相同的细胞。 在上面的例子中,结果被写入到A2。
关于输入...如果你想要的结果,当你改变某些细胞更新,确保这些细胞是参数的VBA函数。
2008年的Mac,不具有VBA这不能在Excel工作。 的Excel for Mac 2011中得到了VBA回来。