The Microsoft documentation here is the sample of the slide I'm trying to download a data from so here we have a data file four of them if I copy this link and paste it here this is the name.
Of the file so that is what I'm we are trying to download today similarly we will try it for other files down here ok once we're done with our function we will you know I put a file pot here we.
Put a button and try to download it let's get started first so let's write a quick stop out routine so download download file and then we'll say dim download status as Bleen dim URL.
As string and then we'll say team destination file name or a local file name as string this will all be text and then we'll see the URL is gonna come from this cell so the say d3 they say d3.
And then the URL destination file name let's see I want to put this downloads folder here so for now we'll just start this with a simple this is the destination where I want to put.
The file and then of course this will come with the file name as well so we'll take your that in a bit and then the function so we'll see download status is equal to URL download from file so let's.
Start this well ignore the first parameter we'll just give it it's false and then we want downloaded from the URL and then we'll specify the destination folder and we'll just ignore the rest of.
The parameters okay so it says file name it's not defined so I'll say team actually let's write a quick functions a function or just ignore this for now we'll write a quick function just to get.
File name from the URL so function file name and then we'll get this from file full name a string we want to return a string so the file name is equal to so if we give me one moment so if we pass.
This URL we want to return a file name so so that every time you download you can directly you know like return us that's 500 dots it ok so that's what we're trying to do okay so do this we'll.
Posts Related:
- Python Part 17b - VBA using pywin32 Office
- Excel VBA Introduction Part 5 - Selecting Cells (Range, Cells, Activecell, End, Offset)
- Excel VBA Introduction Part 57.8 - Printing in Google Chrome using Selenium
Just use a simple mid function and then
The in string function so we'll quickly do this so meat and then we'll just save this file name and then we'll just use in string.Until this will just divide the file by we have so if you're using the local file part we'll use the back slash but in this scenario is the web service use this and then we'll just close the.
Bracket and then we'll add one more to the string just to so that you know like the dot part is included in the logic so if I try to do this now let's just try the test this function quickly so it.
Gives us the file name so I'll say here and then we want to get a file name from D to was it detail yeah d3 sorry so d3 whatever is there Oh in d3 we want to get a file name of that URL so if I.
Just debug this right now it's gonna give us this so this is I want this to be downloaded to the Downloads folder call the file name as this okay okay so our function is ready let's give it a.
Quick go let me just change this to variant for now this is basically gonna return a 0 if it is successful so let's just give it a shot so if download status is equal to zero then else if it.
Is downloaded successfully let's say like message box downloaded successfully else missus box down failed okay so let's give it a shot I'm gonna run.
This now this is downloaded successful it's very quick if I go to my folder you can see this is us 500 so let's try to give it another try.
I'm just gonna go here let's try to run for another file like us we've done with the u.s. let's download the UK file now let's add a quick button to this maybe a shape something like this we'll call.
This downward file
There's something like this we'll attach our code that we just wrote download file and let's give it a shot so here once we run this it will.Download the UK file download it successfully so you see the UK file is there if I extract this this is the UK file that I just downloaded so guys that's all I have for you today thank.