Downloading File with VBA

Dohko

Board Regular
Joined
Apr 13, 2007
Messages
88
Hi,

How can I write some code to download a file from a website programatically?

Say I want to download abc.xls that is located at www.google.com/abc.xls
and save it to c:\temp\abc.xls.

Without getting any prompts, just overwrite the file if it exists.

Thanks.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Have a look at the Windows API functions URLDownloadToFile or URLDownloadToCacheFile.
 
Upvote 0
Both those functions just download the file, they don't open it. As for in the background, maybe try calling one of them in an Application.OnTime procedure, or search for asynchronous download.

Alternatively, if the file is a .xls, as your URL indicates, Excel itself can download it. Try File - Open - the URL with the macro recorder running to generate the VBA code.
 
Upvote 0
I tried downloading the file, but since its a CSV file it is not the original file once it is saved by excel.

This is what im doing..

Workbooks.Open Filename:="http://blabla.com/table.csv"
Application.DisplayAlerts = False
Windows("table.csv").Activate
ActiveWorkbook.SaveAs Filename:="C:\blabla\export.csv", FileFormat:=xlCSV _
, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False

Can someone show me how to copy the file without opening it perhaps?
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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