Results 1 to 2 of 2

Thread: VBA macro problem with Internet Explorer 9, Error -2147417848

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    1

    VBA macro problem with Internet Explorer 9, Error -2147417848

    Hi there, this is my first post so please be nice =)
    I have a problem which has been driving me crazy for the last two weeks. I have tried Google and other forum entries but couldn't get a solution.
    I am using Vista SP2 and Excel 2007 (Office 2007 SP2).

    I have written a larger VBA macro, part of which uses the following procedure:

    ******************
    Public Sub Download_File(ByVal vWebFile As String, ByVal vLocalFile As String)

    Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    'Open socket to get the website
    oXMLHTTP.Open "GET", vWebFile, False

    'send request
    oXMLHTTP.Send

    'Wait for request to finish
    Do While oXMLHTTP.ReadyState <> 4
    DoEvents
    Loop

    oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

    'Create local file and save results to it:
    vFF = FreeFile
    If Dir(vLocalFile) <> "" Then Kill vLocalFile
    Open vLocalFile For Binary As #vFF
    Put #vFF, , oResp
    Close #vFF

    'Clear memory
    Set oXMLHTTP = Nothing
    End Sub
    ******************

    I retrieved this code a while ago from some website (I can't remember the URL anymore) and adapted it for my purposes. The basic idea is to send a XMLHTTP request to the target URL (vWebFile ) and save the response to a local text file (vLocalFile). I chose this method as it was the fastest and most reliable way of downloading the data from the webpage.

    The code has been working beautifully for over a year while IE8 was installed on my machine. However, after installing Internet Explorer 9, Excel throws the following exception:
    "Method 'send' of object 'IXMLHTTPRequest' failed (-2147417848)".
    Even more worryingly, if I execute the request twice in a row, Excel (consistently) stops responding altogether and crashes.

    I have tried referencing different versions of Microsoft XML and setting oXMLHTTP accordingly, yet the situation remains unvaried. Google tells me that some features of XMLHTTP requests are no longer supported (?) in IE9, which may be the root of my problem. I must admit that my understanding of the problematic is quite limited and that getting the code to work in IE8 was based on trial and error in the first place.

    Anyway, if anyone out there has any suggestions on how to work around this problem, I shall be deeply thankful!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA macro problem with Internet Explorer 9, Error -2147417848

    have you tried using the urldownloadtofile API to do the same thing?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width