我可以在Excel 2010 VBA中进行异步XML调用吗? [英] Can I do an async XML call in Excel 2010 VBA?

查看:200
本文介绍了我可以在Excel 2010 VBA中进行异步XML调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的电子表格中,我参考了MS XML v3库。



这是我的示例代码

  Option Explicit 


私有objConn作为XMLHTTP30


公共Sub HandleAsyncEvent()
Debug.PrintDone
End Sub

公共功能InitService(serviceUrl As String,可选asyncMode As Boolean = True)
设置objConn =新建XMLHTTP30
objConn。打开POST,serviceUrl,asyncMode
objConn.setRequestHeaderContent-Type,text / xml
objConn.onreadystatechange = HandleAsyncEvent

结束函数

当我遇到一个运行时异常,当它涉及到

  objConn.onreadystatechange = HandleAsyncEvent 

Excel抛出异常需要对象



这是否真的有可能将函数传递到 onreadystatechange ?我可以在excel vba中传递一个函数pointer吗?

解决方案

这是一种这种类型任务的方法: >

http: //www.dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/


In my spreadsheet I have a reference to the MS XML v3 library.

Here is my sample code

Option Explicit


Private objConn As XMLHTTP30


Public Sub HandleAsyncEvent()
    Debug.Print "Done"
End Sub

Public Function InitService(serviceUrl As String, Optional asyncMode As Boolean = True)
    Set objConn = New XMLHTTP30
    objConn.Open "POST", serviceUrl, asyncMode
    objConn.setRequestHeader "Content-Type", "text/xml"
    objConn.onreadystatechange = HandleAsyncEvent

End Function

I encountered a runtime exception when it comes to the line

objConn.onreadystatechange = HandleAsyncEvent

Excel throws the exception "Object required"

Is it actually possible to pass a function into onreadystatechange here? Can I pass a function "pointer" around in excel vba?

解决方案

Here's an approach to this type of task:

http://www.dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/

这篇关于我可以在Excel 2010 VBA中进行异步XML调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆