VBA to Save As from IE 11 Download Bar

angusfire

New Member
Joined
Feb 24, 2012
Messages
34
I have the following code to download a file from the web but I have to manually do a Save As.

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]  Dim Filename As String
  Dim ieApp As Object
  Dim URL As String
  
    URL = Range("All_Quad_URL")
    Filename = "C:\Historic_Weather_Data\Precipitation\" & Range("File_Name").Value[/FONT]


[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    Set ieApp = CreateObject("InternetExplorer.Application")
    ieApp.Visible = True
    ieApp.Navigate URL
      
      While ieApp.Busy Or ieApp.ReadyState <> 45
        DoEvents
      Wend

[/FONT][FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    ieApp.Quit
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    Set ieApp = Nothing
[/FONT]

I would like to automate the Save As and I have tried to use the following method but am unable to get it to work.

I am also getting a "Run-time error '-2147467259 (80004005)': Method 'Busy' of object 'IWebBrowser 2' failed" that debugs to the While ieApp.Busy line.

Any help is appreciated.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Sending keys is not very reliable, but worked for me in this case:

Code:
Sub Scrapper()
Dim ie As Object, doc As Object
Set ie = GetIE                  ' get IE window with the desired bar
ie.Visible = True
Set doc = ie.Document
doc.Focus                       ' bring to front
Application.SendKeys "%{S}"     ' ALT + S to save
End Sub


Function GetIE() As Object
Dim sa As Object, sw As Object, ieo As Object, obw, sn$
Set sa = CreateObject("Shell.Application")
Set sw = sa.Windows()
On Error GoTo 0
For Each obw In sw
    If (Not obw Is Nothing) Then
        sn = obw.Name
        If sn = "Internet Explorer" Then
            Set ieo = obw
            Exit For
        End If
    End If
Next
Set sa = Nothing
Set GetIE = ieo
End Function
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top