Can I do an async XML call in Excel 2010 VBA?

拟墨画扇 提交于 2019-12-08 10:13:41

问题


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?


回答1:


Here's an approach to this type of task:

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



来源:https://stackoverflow.com/questions/9866930/can-i-do-an-async-xml-call-in-excel-2010-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!