logo
Microsoft Excel - Interview Questions and Answers
How do we check whether a file exists or not in a specified location?
Sub CheckFileExists()

Dim strFileName As String

Dim strFileExists As String

    strFileName = “File location\file_name.xlsx”

    strFileExists = Dir(strFileName)

   If strFileExists = “” Then

        MsgBox “The selected file doesn't exist”

    Else

        MsgBox “The selected file exists”

    End If

End Sub