Download Report from a Website

nianchi111

Board Regular
Joined
Aug 24, 2007
Messages
197
Office Version
  1. 365
Hi Friends,

I have a website where I have to download 100s of reports. I have created a macro that will open the website, log in, and update the date range and then download the report one by one.

the current challenge is that once after downloading at the bottom of the IE a dialog box appears with Open, Save and Save As.

a (2).jpg


I need to Save the downloaded file to a folder with the names from column A.

Looking forward to a positive response.

Thanks,
Vimal
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Sub GoToWebsiteTest()
Dim eventChange As Object
Dim appIE As InternetExplorerMedium
Set appIE = New InternetExplorerMedium
sURL = "https://Test"
With appIE
.navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.readyState <> 4
DoEvents
Loop
Set eventChange = appIE.document.createEvent("HTMLEvents")
eventChange.initEvent "change", True, False
With appIE.document.getElementsByName("Reports")(0)
.selectedIndex = 3
.dispatchEvent eventChange
End With
Do While appIE.Busy Or appIE.readyState <> 4
DoEvents
Loop
appIE.document.forms(0).all("DateFrom").Value = Range("C2").Value
appIE.document.forms(0).all("DateTo").Value = Range("C4").Value
appIE.document.forms(0).all("Shop").Focus
appIE.document.forms(0).all("Shop").Click
appIE.document.forms(0).all("Shop").selectedIndex = 2
appIE.document.forms(0).submit
Set appIE = Nothing
End Sub

a (2).jpg

This is the Code I have created searching so many websites and the last part once the report is downloaded it has to be saved in the folder with the name which is mentioned in cell A2.
 
Upvote 0
As shown in the example Test routine in my linked posted, call the IE_Download_File_Using_UIAutomation function immediately after the line which causes IE's download notification bar to appear (the submit line in your case), with the associated arguments, like this:

VBA Code:
    Dim saveAsFullName As String
    Dim replaceExistingFile As Boolean
    Dim downloadResult As String, downloadStatus As Boolean
    
    saveAsFullName = ActiveSheet.Range("A2").Value          'Save in this folder with the file name provided by web site
    If Right(saveAsFullName, 1) <> "\" Then saveAsFullName = saveAsFullName & "\"   'Folder must end with "\"
    replaceExistingFile = True
    
    downloadStatus = IE_Download_File_Using_UIAutomation(IE.hwnd, saveAsFullName, replaceExistingFile, downloadResult)
    Debug.Print "Download result = " & downloadResult
    Debug.Print "Download saveAsFullName = " & saveAsFullName
    Debug.Print "Download status = " & downloadStatus
 
Upvote 0
As shown in the example Test routine in my linked posted, call the IE_Download_File_Using_UIAutomation function immediately after the line which causes IE's download notification bar to appear (the submit line in your case), with the associated arguments, like this:

VBA Code:
    Dim saveAsFullName As String
    Dim replaceExistingFile As Boolean
    Dim downloadResult As String, downloadStatus As Boolean
   
    saveAsFullName = ActiveSheet.Range("A2").Value          'Save in this folder with the file name provided by web site
    If Right(saveAsFullName, 1) <> "\" Then saveAsFullName = saveAsFullName & "\"   'Folder must end with "\"
    replaceExistingFile = True
   
    downloadStatus = IE_Download_File_Using_UIAutomation(IE.hwnd, saveAsFullName, replaceExistingFile, downloadResult)
    Debug.Print "Download result = " & downloadResult
    Debug.Print "Download saveAsFullName = " & saveAsFullName
    Debug.Print "Download status = " & downloadStatus

Thank you so much !!!
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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