+ Reply to Thread
Results 1 to 4 of 4

trouble with saving file to directory

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Question trouble with saving file to directory

    How do I check to see if a directory exist before saving workbook

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: trouble with saving file to directory

    Try this,

    Edit: I forgot to mention, you only need the full path of the directory you want to check.
    Sub FilePath()
      Dim fPath
     On Error GoTo Ext
         fPath = "C:\YourPathHere"
        If Not Dir(fPath, vbDirectory) = vbNullString Then
           MsgBox "Folder exists"
        Else
          MsgBox "Folder does not exist"
        End If
        
    Ext:
        On Error GoTo 0
    End Sub
    Last edited by JapanDave; 04-23-2013 at 09:07 PM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: trouble with saving file to directory

    Thank You for the help with this, it works great.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: trouble with saving file to directory

    Check out this example.
    Click the button, a userform will pop up and a combobox will populate with the folders in the C drive and the textbox will show what is in Range("L10")
    Select a folder and click "Make New Folder" A folder will be made with the name that is in the textbox.
    Click the button again, select the same folder in the combobox and click "Make New Folder"

    You will get a message box telling you that the folder already exists.

    It would be a good idea to first make a test folder in the C drive for experimental purposes.
    Then you can select the test folder in the combobox
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1