Vba Access Download File From Web

Sub DownloadFile Dim myURL As String myURL = 'Dim WinHttpReq As Object Set.

Active1 year, 3 months ago

I am trying to automate a file downloading from a website. When I do the download manually, all I have to do is to click on the 'save' icon (floppy disk), then another window pops up for a second and the download begins (while the popped up window disappears).

What I usually do (when I automate a download) is to find the files URL, then I use the URLDownloadToFile function. But in this case I cannot find the url in the html. I tried to use the .click and FireEvent on the object but nothing worked.

So I started to think (based on similar question in this site) that a script generates the URL when I press the 'save' icon. Unfortunately I am not familiar with javascript or how it works. Right now I am trying to use my browser's developer tools's console to figure out what happens when I click the object. BTW: this object is an <img> object.

I searched the web for answers, and I think that somehow I will have to call the javascript myself if I want to download the file, with something like execScript. But how do I find out which script gets called when I click on the icon? And more importantly will I be able to understand your answer without completely understanding how a webpage works? :)

P.S.: I know it would be far easier if I could give you the site address, but it requires a login to see the stuff that I am talking about...

Edit #1:

This is the HTML code of the said object:

And when I look it up on eventListener I can see that it has a 'click' event. It says this:

EventListener:

EventListener Unwrapped:

GIF of me goofing around on the site (downloading the file):

Edit #2:

Sorry guys, I worked multiple days on this 'project', and I totally forgot, that if I simply locate the <img> object, and do a .Click it will download the file. BUT! IE makes a pop-up window with options like 'Save, SaveAs, Cancel'. I know that there are multiple questions about how to deal with this popup window, but I think my question still stands. Because the best solution would be to find the URL that is generated, and download that link with e.g. URLDownloadToFile. This way I wouldn't have to interact with IE's popup window. I hope this clear things up a little.

omegastripes
9,4472 gold badges23 silver badges61 bronze badges
MRK_SMRK_S

2 Answers

Assuming you are trying to download the image -
Have a look at How do I base64 encode a string efficiently using Excel VBA?There you'll find a Decode method. Use that on the base64 portion of the url, that is the text between &quot;data:image/png;base64, and &quot;. Save that as a binary file and you have your image.

SamSamMs access vba download file from url
3,4271 gold badge7 silver badges24 bronze badges
ryguy72

Ms Access Vba Download File From Url

ryguy72
4,8451 gold badge9 silver badges31 bronze badges

Not the answer you're looking for? Browse other questions tagged vbaexcel-vbaweb-scrapingautomationxmlhttprequest or ask your own question.

Posted :