How to Automate the download of a file from a website

I have set up functionality within an Access database that will allow users to import data from a spreadsheet that the user has to download from our Supplier website.

In order to further streamline this process, is it possible to somehow automate the download from the supplier website?

Further information:  In order to download the information required, the user must go to the supplier website, input login details, select the correct options to bring them to the necessary page, to then populate date controls and select from a customer code list and finally to choose to export to Excel.

Is this possible, or would it be a better bet to ask the supplier if they could automate the delivery of this information in some way?
Who is Participating?
slubekConnect With a Mentor Commented:
1. Find an URL from which you want to download file - do it as /gustav told by watching the http calls (I'm using Firefox Live Http Headers add-on)

2. When you know URL, you can download file with:
Declare Function URLDownloadToFile Lib "urlmon" Alias _
    "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) As Long

Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal      As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

Private Sub test()
    Debug.Print DownloadFile("", "C:\Data\file.txt")
End Sub

Open in new window

If you want to use user authorization, you can use it with "" form.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You should first ask the supplier if they allow automation of their site. In some cases, this would be a violation of their Terms of Use.

If they do provide automation, you'll often find that those methods are not easily used in Access - they often require you to issue web-centric calls to the site's automation engine, which Access often has difficulty doing.

If they don't provide automation, but have no problem with you doing this, then you can try using a Web Browser control on your Form. Here's the MSDN reference for the WebBrowser:
Gustav BrockCIOCommented:
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

thechrisrobertstooAuthor Commented:
Thanks Gustav, but I'm not trying to download either an image or a web page, I'm trying to run the export functionality that's built-in to the website.

LMConsulting:  That seems a little over-involved.  I already have the functionality to import the data once it has been downloaded.  I don't especially have a need to achieve the download via an Access form.  It could just be a script that gets run daily as a scheduled task.
Gustav BrockConnect With a Mentor CIOCommented:
Oh, missed that part.

Then you'll have to put your browser in debug mode and study the calls and returned values during a session. Then find out how to mimic a session with the browser object.

I have done similar things in C# but have no idea how to achieve this in VBA.

thechrisrobertstooAuthor Commented:
Anyone able to help with this for VBA or with an independent schedule-able task?
thechrisrobertstooAuthor Commented:
Thanks Slubek, that looks great.  There is an added difficulty in that the login screen has a variable code that also has to be typed in, which of course is an image.

Sorry, I'd forgotten that, I think I've probably wasted everyone's time.  Those image codes are designed to thwart this kind of automation, aren't they?
Gustav BrockCIOCommented:
Ha ha, yes they are.
However, you could automate the process up to the presentation of the image - and perhaps to continue after the manual typing.

thechrisrobertstooAuthor Commented:
Ok.  I appreciate all the help.  I'll try this out in while as I've been overtaken by another project.  I may restart some correspondence when I have time to work on this again.

I think that the best way is to ask your supplier for help. The files are rather strong secured, so I suppose you pay them rather big money and they should help you to get the files without CAPTCHA.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.