Home>Blogs>VBA>Check Folder Existence using VBA
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

Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!