Skip to Main Content
Excel 2003 Programming: A Developer's Notebook
book

Excel 2003 Programming: A Developer's Notebook

by Jeff Webb
August 2004
Intermediate to advanced content levelIntermediate to advanced
312 pages
8h 30m
English
O'Reilly Media, Inc.
Content preview from Excel 2003 Programming: A Developer's Notebook

Call a Web Service Asynchronously

One advantage of calling a web service directly, rather than through proxies, is that it is very easy to handle the response asynchronously. The DOMDocument object provides an ondataavailable event that occurs when the object is finished loading XML from a source. This means that you can launch a web service request, release control to the user, and display results when a request is complete. Being able to handle a response asynchronously is especially important when the web service is returning a large amount of data.

How to do it

To use the DOMDocument object to respond to a web service asynchronously, follow these steps:

  1. Declare a DOMDocument object at the module of a class. The class can be a workbook, worksheet, or code class module. For example, the following variable is declared in the wsAmazon worksheet class:

    	                       Dim WithEvents xdoc As DOMDocument
  2. Select the xdoc object from the object list at the top of the code window, and then select ondataavailable from the event list to create an empty event procedure as shown here:

       Private Sub xdoc_ondataavailable(  )
    
       End Sub
  3. In other code, initialize the xdoc object, set its async property to True, and then call the web service using the xdoc object’s Load method. For example, the following event procedure searches Amazon.com for a keyword when the user clicks the Get Titles button on the wsAmazon worksheet:

     Sub cmdTitles_Click( ) Dim SearchUrl As String ' Create a new DOMDocument and set ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office Excel 2003 Programming Inside Out

Microsoft® Office Excel 2003 Programming Inside Out

Curtis Frye, Wayne S. Freeze, Felicia K. Buckingham
Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Office 2003 XML

Office 2003 XML

Simon St. Laurent, Mary McRae, Evan Lenz

Publisher Resources

ISBN: 0596007671Supplemental ContentCatalog PageErrata