+ Reply to Thread
Results 1 to 4 of 4

If Directory Exists

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Unhappy If Directory Exists

    I'm working on a macro that creates files and folders on the fly based on variables within the content.

    I need to write in an 'IF' clause that if the directory already exists: save file to
    else
    create directory.

    Would anybody be able to help with the Checking if a Directory exists part?
    Last edited by TonyforVBA; 10-25-2011 at 10:18 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: If Directory Exists

    If Dir("some path", vbDirectory) = "" Then
       ' it doesn't exist
    Else
        ' it does exist
    End if
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Re: If Directory Exists

    Perfect, Thanks for that.

  4. #4
    Registered User
    Join Date
    03-21-2011
    Location
    Ringgold GA
    MS-Off Ver
    2016
    Posts
    27

    Re: If Directory Exists

    I'm having issues getting this to work.. Always comes back "it doesn't exist"

                If Sheets("Panel").Cells(X, 6).Value = "Yes" Then
                    '=============================================
                    ' PDF them
                    '=============================================
                        Sheets("Panel").Visible = False
                            If Sheets("Panel").Cells(X, 22).Value = "Published" Then
                                filepathname = Sheets("Panel").Cells(X, 24).Value
                            Else
                                filepathname = Sheets("Panel").Cells(X, 23).Value
                            End If
                                
                                'Build Path
                                FileCheckPath = filepathname & Sheets("Panel").Cells(X, 20).Value
                                filepathname = filepathname & Sheets("Panel").Cells(X, 20).Value & "\" & Sheets("Panel").Cells(X, 25).Value & "_PMP"
                                
                                'Add date if it is requested
                                If Sheets("Panel").Cells(X, 21).Value = "Yes" Then
                                filepathname = filepathname & "_" & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now())
                                End If
                                
                                'Add file extension ;0)
                                filepathname = filepathname & ".pdf"
                                
                                'Does directory exist?
                                MsgBox (FileCheckPath)
                                If Dir(FileCheckPath, vbDirectory) = "" Then
                                   MsgBox ("it doesn't exist")
                                Else
                                    MsgBox ("it does exist")
                                End If
                                
                        Sheets("Panel").Visible = True
                        Sheets("Panel").Activate
                    '=============================================
                End If

    Never mind! Built the path wrong..
    Last edited by KillGorack; 11-15-2011 at 03:51 PM.

+ 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