Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Check if a File or Folder Exists using File System Object


You can access and modify files and folders using the FileSystemObject in VBA. Just Add the Reference "Microsoft Scripting Runtime".

' Add Reference to Microsoft Scripting Runtime

Sub CheckFolderExist()
Dim MyFSO As FileSystemObject
Set MyFSO = New FileSystemObject
If MyFSO.FolderExists("C:\VBAUSEFULCODES\TESTFOLDER") Then
    MsgBox "The Folder Exists"
Else
    MsgBox "The Folder Does Not Exist"
End If
End Sub

Sub CheckFileExist()
Dim MyFSO As FileSystemObject
Set MyFSO = New FileSystemObject
If MyFSO.FileExists("C:\VBAUSEFULCODES\TESTFOLDER\Test.xlsx") Then
    MsgBox "The File Exists"
Else
    MsgBox "The File Does Not Exist"
End If
End Sub


Subscribe

Enter your e-mail below and get notified on the latest blog posts.




Tags

VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts


Follow Us