I received this question this morning and it was regarding I have a video on
saving saving files with a macro to a specific location on on your computer
and he says I followed your instructions and it worked I would like a display
alert and prompt you yes you know you could saving a duplicate well I was
thinking about that and I thought that that was probably a pretty good idea I
have here a little little thing here and I got my button isn't named and I this
is c4 is where is the name of the file I'm going to save it to now if I click
the button one it's supposed to save first test there and then it comes up
with file already exists so this would be helpful if you have number of people
working on the file and you would like like to know whether it's being saved
already so let me show you what the code looks like so I will include this code
in in my description this is basically my same old file that I'm using to save
save a file and specific location so it's dim path has string dim filename
one as strength and path equals c users bar penderson desktop demo so i have i
have a demo on my desktop and i have first text first test xml SL this is
with the macro in and this is the file that it's saving so that's why you
didn't save because we already have a test in here now to get the path I'll
review this basically what you do is you click in there and you get you copy this
and you can see that that's exactly the path here and don't forget the closing
backslash and the closing quotation marks on your quotation marks on both
sides of it so that's the path and as I was saying before range c4 is what my
name of the file is going to be and so now just so the ease of this we've
display alerts equals false we've turned off the things but here we're testing
that it's going to search the path and the filename and if that file already
then it's gonna send a message box file exists is and it's a go-to statement and
I have an T which is just meaning that's skipping all the rest of steps and going
to end a sub so if so if it finds it then this case can tell you that file
exists and go to nd now if it doesn't find it then it's gonna go active
workbook save as then space filename equals path and file name so path with
an ampersand file name one which is our range ec4 and the extension ampersand
and then the extension in quotation marks
xlsx and then comma file format Excel open Excel and workbook and then and if
applications now we're turning the app display alerts back on and then we're
going to close the workbook that we're working on so let's go back to my file
and let's change first test let's change it to second test okay so now let's so
now let's f8 through my code here and so we're gonna start with the beginning and
see how it goes we've gone through there and it's found
the path and the filename c4 which is 2nd test now and they were changing off
the - turning off our display alerts and then it's saying is it is this one
already exists and it doesn't so now it's gone to the next one and it's gonna
save as file name path second test in the just desired location and if and
then what we're gonna do is - we're turning on display alerts and then we're
it's gonna close our active workbook okay so now let's go back to my my demo
here and there you go we have first test and first test and then second test so
it will not save me if it already exists but it will save but if it's a
new file name into the same directory that's how you test to see if the file
already exists before you save it in a specific location please subscribe