Forum Discussion

wuzmop's avatar
wuzmop
Copper Contributor
Feb 23, 2018

True or False if file exists in a folder

I'm trying to write an IF formula that would return T or F if a file exists in a network folder. Can someone help? Thanks

  • Jamil's avatar
    Jamil
    Bronze Contributor

    You cannot get what you are asking with built-in formulas. If you know how to use VBA User Defined Functions. then here is already an answer for this question using UDF.

     

    Public Function CheckIfFileExists(FilePath As String)
    
    On Error GoTo ExitWithError
    
    If FilePath = "" Then
        CheckIfFileExists = ""
        Exit Function
    End If
    If Dir(FilePath) <> "" Then
        CheckIfFileExists = "File found"
    Else
        CheckIfFileExists = "File not found"
    End If
    
    Exit Function
    ExitWithError:
        CheckIfFileExists = "File not accessible"
    End Function

Resources