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 Check Folder Existence.
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.
Image-1
Check Folder Existence
Below the VBA code for Folder Existence Function.
Option Explicit Function Folder_Existence(MyPath As String) As Boolean Application.Volatile If VBA.Dir(MyPath, vbDirectory) = "" Then Folder_Existence = False Else Folder_Existence = True End If End Function
Click here to download this Excel workbook for practice.
Watch the step by step video tutorial
Visit our YouTube channel to learn step-by-step video tutorials