vba 如何从excel宏调用Web服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5257989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call web service from excel Macro
提问by Eshwer
I need to call an webservice method from my excel macro. can any on suggest me how can i do that. I don't want to use soap related thing durin calling the webservice in macro code.
我需要从我的 excel 宏调用 webservice 方法。任何人都可以建议我如何做到这一点。我不想在宏代码中调用 web 服务时使用与肥皂相关的东西。
Thanks in advance.
提前致谢。
Eshwer Nayudu
埃什维尔·纳尤杜
采纳答案by i_saw_drones
If you don't wish to use the SOAP type library, you could use MSXML instead and create the SOAP request manually in code and then post it to the web service.
如果您不想使用 SOAP 类型库,则可以改用 MSXML,并在代码中手动创建 SOAP 请求,然后将其发布到 Web 服务。
Please take a look at http://www.freevbcode.com/ShowCode.asp?ID=7611for a nice example. It's for VB6, but I am sure it would need little adjustment for VBA.
请查看http://www.freevbcode.com/ShowCode.asp?ID=7611的一个很好的例子。它适用于 VB6,但我相信它几乎不需要对 VBA 进行调整。
回答by John Saunders
The best way to do this is to create a simple class which acts as a WCF client to the service. Then, with just a little more work, you can turn this class into a COM object. Excel can easily access COM objects.
最好的方法是创建一个简单的类,作为服务的 WCF 客户端。然后,只需多做一点工作,您就可以将此类转换为 COM 对象。Excel 可以轻松访问 COM 对象。