VBA excel是否可以调用API DataRoboot



在VBA中,我们可以使用VBA excel从预测数据机器人调用API吗?

有人知道模板脚本吗?感谢

是的,您可以使用VBA发送API请求!下面是我用来做简单API请求的非常基本的函数。它适用于大多数网站上的GET请求。对于POST或PUT,您需要知道它们的特定URL方案和正文文本格式。

Private Function XML_API( _
ByVal URL As String, _
ByVal Action As String, _
Optional Body As String = "") As String

Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.Open Action, URL, False

'Default Headers
http.setRequestHeader "Content-Type", "application/xml"
''''''''''''''''
'Send
If Body <> "" Then
http.Send CVar(Body)
Else
http.Send
End If

'Interpret Response
If http.Status = 200 And Action <> "GET" Then
XML_API = "Successfully Sent!"
Else
If http.Status <> 200 And http.responsetext = "" Then
XML_API = http.statustext
Else
XML_API = http.responsetext
End If
End If

End Function

最新更新