1

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?

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304

1 Answers1

2

Here's an approach to this type of task:

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

Tim Williams
  • 154,628
  • 8
  • 97
  • 125