Skip to content

Instantly share code, notes, and snippets.

@brazilnut2000
Created July 5, 2013 20:17
Show Gist options
  • Select an option

  • Save brazilnut2000/5936974 to your computer and use it in GitHub Desktop.

Select an option

Save brazilnut2000/5936974 to your computer and use it in GitHub Desktop.
VBA: Check to see if a given path or file exist
' Code based on snippet from John Walkenbach
Function FileExists(fileName) As Boolean
FileExists = Dir(fileName) <> ""
End Function
Function PathExists(pathName) As Boolean
' Returns TRUE if the path exists
On Error Resume Next
PathExists = (GetAttr(pathName) And vbDirectory) = vbDirectory
End Function
Sub CreateFolderIfNeeded(pathName)
If PathExists(pathName) = False Then MkDir (pathName)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment