Folder Existence Function

Check Folder Existence using VBA

During the automating some task in VBA, many times we need to check that a folder is exits or not. For example if you want to create or delete a folder using VBA then you should check first whether that folder exits for not. If that folder exits then you take your next action. It method can prevent you from an error.

In this article you will learn how to create a User defined function in VBA to check a folder exits for not. This function will return True for False.


Below the VBA code for Folder Existence Function.

Option Explicit

Function Folder_Existence(MyPath As String) As Boolean


If VBA.Dir(MyPath, vbDirectory) = "" Then

    Folder_Existence = False


    Folder_Existence = True

End If

End Function


Click here to download this Excel workbook for practice.


Watch the step by step video tutorial

My Name is PK. I am founder of I am a Microsoft Certified Professional. I have more than 12 years of experience in Data Visualization, Excel Automation and dashboard creation. Excel is my passion and I like to do always something innovative in Excel and share it with other people.