我正在尝试在Excel 2007中编写一个cls,这是代码:
Dim JiraService As MSXML2.XMLHTTP60
Set JiraService = New MSXML2.XMLHTTP60
JiraService.Open "GET", "URL", False
JiraService.SetRequestHeader "Content-Type", "application/json"
JiraService.SetRequestHeader "Accept", "application/json"
JiraService.Send
sRestResponse = JiraService.ResponseText
MsgBox sRestResponse
我收到编译错误,表示Set似乎无效。
它基本上表示外部程序无效。
任何人都可以帮助我吗?
答案 0 :(得分:4)
我猜你错过了相应的参考资料。单击工具~~> VBA中的参考
添加项目引用;
也在这一行
JiraService.Open "GET", "URL", False
如果URL
是保存实际网址的变量,则"URL"
将被视为字符串,而不是变量,因为它位于引号之间。我想你是在尝试这个?
JiraService.Open "GET", URL, False
关注(来自评论)
问题是您已将上述代码粘贴到类模块中。您可以将代码粘贴到模块中并在子模块中调用它。见这个例子
Sub Sample()
Dim JiraService As MSXML2.XMLHTTP60
Set JiraService = New MSXML2.XMLHTTP60
JiraService.Open "GET", URL, False
JiraService.SetRequestHeader "Content-Type", "application/json"
JiraService.SetRequestHeader "Accept", "application/json"
JiraService.Send
sRestResponse = JiraService.ResponseText
MsgBox sRestResponse
End Sub
<强>截图强>