Excel VBA: Validate File Can Be Downloaded

What VBA would I use that would download a file, but before doing so validate the file can be downloaded before attempting the pull. If possible please try to do this without using On ERROR. I'm trying to see if there is a solid way to check if a file can be downloaded without attempting the download first.

  • In the link above it would validate the file can be downloaded before attempting the download. If for any reason the file could not be downloaded a message box would appear stating "The file can not be pulled. The link may have changed."

  • I may have seen someone try to do this using Dos/Shell but couldn't get it to work at the time and don't remember where it is at.
Who is Participating?
Gustav BrockConnect With a Mentor CIOCommented:
There is no way to do that, but just do the attempt.

You can use my DownloadFile (returns and error code) or DownloadCacheFile function (returns the filename if success) found here:

Show pictures directly from URLs in Access forms and reports
ste5anConnect With a Mentor Senior DeveloperCommented:
In the link above it would validate the file can be downloaded before attempting the download
Can you rephrase this?

The long answer: There is no use in a function like this. Cause any test your make before the action can either produce a false positive - the file is downloadable during your test, but removed after your test is done and before you have started the download - or a false false - it reports that the file is not available during that test, but is immediately available after your test is done.

Further more, while we see that the internet is pretty stable, it is built as a mechanism which can have failures. So even when your test function says the file is available for download, the download it self could fail for different reasons.

The short answer: The only function to test, whether a file is downloadable or not, is to download it. When you have retrieved it successfully, then it is downloadable. Otherwise not.
All Courses

From novice to tech pro — start learning today.