得到“没有合适的对象就无效的方法".尝试在VBA中发出HTTP请求时发生错误? [英] Getting "method not valid without suitable object" error when trying to make a HTTP request in VBA?
问题描述
我尝试遵循以下示例: http://libkod.info/officexml -CHP-9-SECT-5.shtml -捐赠
但是它给出了这个错误
在此行:
Dim objHTTP As New MSXML2.XMLHTTP
我尝试使用此示例: http: //msdn.microsoft.com/zh-CN/library/windows/desktop/aa384106(v=vs.85).aspx
您可能尚未在VBA窗口的工具/参考..."对话框中为Dim objHTTP As New MSXML2.XMLHTTP
添加对Microsoft XML
(任何版本)的引用. /p>
此外,最好避免使用后期绑定(CreateObject
...);最好使用早期绑定(Dim objHTTP As New MSXML2.XMLHTTP
),因为早期绑定使您可以使用Intellisense列出成员并进行各种设计时验证.
I tried to follow this example: http://libkod.info/officexml-CHP-9-SECT-5.shtml - Archive.org - Donate
but it gave this error
on this line:
Dim objHTTP As New MSXML2.XMLHTTP
I tried to use this example: How can I send an HTTP POST request to a server from Excel using VBA?
but it gave this error:
on this line:
Print objHTTP.Status
So how do I make a POST REST call in VBA? How do I make a PUT multi-part/form-data file upload REST call in VBA?
Tools > References
Code
Sub SendEmail()
'Dim objHTTP As New MSXML2.XMLHTTP
'Set objhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://localhost:8888/rest/mail/send"
objHTTP.Open "POST", URL, False
objHTTP.send ("{""key"":null,""from"":""me@me.com"",""to"":null,""cc"":null,""bcc"":null,""date"":null,""subject"":""My Subject"",""body"":null,""attachments"":null}")
Print objHTTP.Status
Print objHTTP.ResponseText
End Sub
Reference
WinHttpRequest object: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106(v=vs.85).aspx
You probably haven't added a reference to Microsoft XML
(any version) for Dim objHTTP As New MSXML2.XMLHTTP
in the VBA window's Tools/References... dialog.
Also, it's a good idea to avoid using late binding (CreateObject
...); better to use early binding (Dim objHTTP As New MSXML2.XMLHTTP
), as early binding allows you to use Intellisense to list the members and do all sorts of design-time validation.
这篇关于得到“没有合适的对象就无效的方法".尝试在VBA中发出HTTP请求时发生错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!