Download multiple files using Internet Explorer, rename them and save in specific folder

Nikit Strygin

New Member
Joined
Aug 19, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I am currently trying to make a VBA code which would multiple files from a given URL. These VBA code should do the following things:
1. Open internet explorer ***in the background*** and download multiple files from a link. Basically, to download multiple files I should change file code in the middle of the URL and the file name in the end of the URL. It could be seen in my code attempt. Each file has it specific code (E.g for File 1 the code is "0001", File 2 - "0002" and etc) and names (File 1 - "FileNamed1", File 2 - "FileNamed2"). In the end of the url there is a wildcard character as the files have dates in the end, so I want excel to ignore them;
2. Rename these documents (E.g So for File1 it should be "File1", for File2 it should be "AnotherFile 2" and etc). Files which are downloaded are in .xlsx format;
3. Save renamed files to the specific folder

So, how to do all these actions through vba?

My attempt is below. Hope I have everything explained clearly. Thanks very much in advance!

VBA Code:
Sub LinkFromURL()
    Dim IE As Object, HTMLDoc As Object, URL$
    Application.ScreenUpdating = False
    Set IE = CreateObject("internetexplorer.application")
    filenames = Array("File1", "File2")
    filecode = Array("0001", "0002")
    URLPath = "https://somesite/api/v1/reportdata/" & filecode & "/filename/" & filenames & "*" & ".xlsx"
    For Each file In filenames
    With IE
        .navigate (URL)
        .Visible = False
    End With
    Application.SendKeys "{TAB}{TAB}{ENTER}"
    Application.ScreenUpdating = True
    End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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