Vba check if file exist in folder in Excel

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub IsFileExists()
  3. On Error Resume Next
  4. Dim sFile As String, sTemp As String
  5. sFile = "C:\Users\Guest\Documents\TestFolder\TestFile.xlsx"
  6. sTemp = Dir(sFile)
  7. If sTemp <> "" Then
  8. MsgBox "File exists."
  9. Else
  10. MsgBox "File does not exist."
  11. End If
  12. End Sub


a) Line 6 - If file exists, Dir(sFile) would return Filename. If it does not exist, it would return empty string. The value of string returned is used to determine the existence of file.


You can find similar Excel Questions and Answer hereunder

1) How can I export a WorkSheet as a PDF using VBA?

2) String split in vba in Excel

3) Vba length of an array in Excel

4) How to handle errors in VBA with the handling error methods

5) How can I loop through all WorkSheets and get their names using VBA?

6) How can I set Page orientation, Zoom % , Title Rows and footer using VBA?

7) How can I sort data using VBA?

8) Excel 2010 vba replacement of application filesearch in Excel

9) How can I delete all shapes in a WorkSheet?

10) Vba to return week numbers in Excel


Here the previous and next chapter