VBA FolderExists

The FileSystemObject VBA FolderExists method returns True if the folder exists otherwise it will return False.

VBA FolderExists

fso.FolderExits( folderpath )

A string representing path to the folder.

VBA FolderExists Examples

Below examples assume file “C:\Src\Subfolder” exists and no other folders exist in “C:\Src”.

Set fso = CreateObject("Scripting.FileSystemObject")

Debug.Print fso.FileExists("C:\Src\Subfolder") 'Result: True

Debug.Print fso.FileExists("C:\Src\Other") 'Result: False

Alternatives in Windows

You can also check if the Folder exists in Windows using:

  • CMD EXIST statement – see example below
    if exist "C:\Somefolder\" (echo "File found" ) else (echo "File not found")
  • Powershell Test-Path commandsee Microsoft documentation here