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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior 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.
Gustav BrockCIOCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.