lundi 20 avril 2015

Automation of IE via VBA executes as intended, but throws an automation error

I have the following code, which is supposed to open Internet Explorer in order to download a file.

Sub hentRapport()
  Dim IEapp As Object
  Dim WebUrl As String

  Set IEapp = CreateObject("InternetExplorer.Application") 'Set IEapp = InternetExplorer
  WebUrl = Oversikt.Range("Adresse")

  With IEapp
    .Silent = True 'No Pop-ups
    .Visible = True 'Set InternetExplorer to Visible
    .Navigate WebUrl 'Load web page

    'Run and Wait, if you intend on passing variables at a later stage
    Do While .Busy
        DoEvents
    Loop

    Do While .ReadyState <> 4
        DoEvents
    Loop
  End With
End Sub

Internet Explorer (IE 11.0.9600.17691) opens as expected, and I get up the dialog for downloading the file, but at the same time I get an error from the macro:

enter image description here

The error happens on the line

Do While .ReadyState <> 4

and I can't figure out why. Doesn't that line simply state that Excel doesn't need to wait for IE to do its thing before accepting other input?

Aucun commentaire:

Enregistrer un commentaire