Altova Mailing List Archives

Trouble using XMLHTTP in VBA (Excel Add-in)

From: =?iso-8859-1?Q?Dag_=D8ystein_Johansen?= <DagOystein.Johansen@----.--->
Date: 8/5/2003 6:43:00 AM

I'm making an add-in for Excel which connects to a web 
application to fetch data and place into spreadsheets. I 
use the XMLHTTP object to make my requests. It's fairly 
straightforward, yet I'm struggling with some (to me at 
least) strange problems. 

After executing the request I assign a module-level 
variable with the xmlhttp.responseXML and use this to look 
up results for individual cells in the spreadsheet:

 With xmlHttp
    .open "POST", serviceUrl, false
    .send requestDoc
    Set responseDoc = .responseXML
 End With

Here's the funny thing. If I put a breakpoint at the Set 
statement, and either step trough the code that follows or 
just runs again, then all is fine. But if I don't have any 
breakpoint there, responseDoc is Nothing (VB's null). 

Unlike the DOMDocument, the xmlHttp doesn't have any async 
property (or equivalent functionality). I tried to set 
xmlhttp.responseXML.async = false, but it makes no 
difference. I figured if xmlhttp.send returned 
asyncronously it could be fixed by setting the async of 
the document false. After all, either send() or the 
responseXML accessor must load the response body in order 
to return the document! 

I have no idea what is going on here and even started to 
wonder briefly if the xmlhttp object might itself set 
async true before loading the xml! (If so, it's restoring 
the state again - async is still false after I read the 
responseXML property.) My final attempt to work around 
this (instead of understanding it and correcting it 
maybe..?) was to insert a waiting loop, to guarantee that 
no further code runs before the readystate of the document 
is complete (4 in MSXML...), but this doesn't make any 
difference either..:

  ' absolutely nothing....
Loop Until xmlHttp.responseXML.readystate = 4

ANY ideas??? Help would be greatly appreciated. 


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.