XLA routines: EE_CheckPaths

Nick's picture
EE_CheckPaths takes a range containing file paths, and checks to see if they all exist. - very useful at the start of a routine that depends on files existing. - check the paths and exit if they don't exist
Function EE_CheckPaths(rngPaths As range, Optional blnDispMissingMsg As Boolean = True) As Boolean
'- takes a range of cells containing file paths / folders.
'- checks if they exist
'- returns false if any 1 doesn't exist
'- displays messagebox with list of missing paths
    Dim strMissingPaths As String
    Dim rngEachPath As range
'http://excelexperts.com/xla-routines-eeCheckPaths    for updates on this function
    For Each rngEachPath In rngPaths
        If rngEachPath.value <> vbNullString Then
            If Not EE_FileFolderExists(rngEachPath.value) Then
                strMissingPaths = strMissingPaths & vbLf & rngEachPath.value
            End If
        End If
    Next rngEachPath
    If strMissingPaths <> "" Then
        EE_CheckPaths = False
        If blnDispMissingMsg = True Then
            MsgBox "Folder/File path(s) not found:" & vbLf & strMissingPaths, vbCritical, "Missing path"
        End If
        EE_CheckPaths = True
    End If
    Set rngEachPath = Nothing
End Function