If folder doesn't exists

  • Have to code to save files to, but get error if the folder doesn't exist.Need a message box to say folder does not exist do you want to save in Misc. folder C:\Users\Tom\Retail\Sales\Misc yes or no option. no woulds
    exit the sub and yes would save.

  • Re: If folder doesn't exists


    Hi there,


    Looks like you want something along the lines of this

  • Re: If folder doesn't exists


    Here is the code I use now,works perfect if folder exists. Range C13 is the folder name

  • Re: If folder doesn't exists


    Quote from zplugger;738213

    Here is the code I use now,works perfect if folder exists. Range C13 is the folder name


    This doesn't show me where & how you've tried to incorporate the new code.

  • Re: If folder doesn't exists


    Sorry
    was using example and had problems. Here is the code.


  • Re: If folder doesn't exists


    try this

  • Re: If folder doesn't exists


    It has to be in this part of code, I can make a simple folder Like (Sales) on C drive and it does not see it?


  • Re: If folder doesn't exists


    fix for the problem if so

  • Re: If folder doesn't exists


    Quote from zplugger;738341


    Dim strFolder AsString'Folder to check the existence of with a \ at the end
    strFolder = "c:\Sales


    The problem is also fixed if you include the "\" as per the comment which you have not done in your code. This can be picked up & corrected with

    Code
    If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"


    after you have assigned a value to strFolder

  • Re: If folder doesn't exists


    No worries zplugger. I must admit, I use the Dir() function mostly for folder checking & have always worked on the basis that e.g. Dir("C:\Test\") implies a folder or a diretory, but with Dir("C:\Test") it implies a file.


    Though that might not exatly be the case having read up with microsoft https://msdn.microsoft.com/en-…k008ty4%28v=vs.90%29.aspx


    I should maybe be more explicit with Dir for folders.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!