The below VBA function uses the Dir VBA function to validate Folder Path.
'This function checks if given folder path is valid or not
Public Function CheckFolderExist(strFolderPath As String) As Boolean
'If Dir retunrs blank then it is invalid folder path
If Dir(strFolderPath, vbDirectory) = "" Then
CheckFolderExist = False
MsgBox "Invalid Folder Path!", vbCritical
'Else it is a valid folder path
Else
CheckFolderExist = True
MsgBox "Valid Folder Path!", vbInformation
End If
End Function
Explanation:Â If the function returns True then it is a valid folder path. If function returns False then it is invalid folder path.
Below VBA function uses File System Object to validate Folder path
'This function checks if given folder path is valid or not
'Microsoft Scripting Runtime reference is required to run this code
Public Function CheckFolderExist(strFolderPath As String) As Boolean
Dim objFileSystem As FileSystemObject
Set objFileSystem = New FileSystemObject
'If FolderExists function returns True then it is valid folder path
If objFileSystem.FolderExists(strFolderPath) = True Then
CheckFolderExist = True
MsgBox "Valid Folder Path!", vbInformation
'Else it is invalid folder path
Else
CheckFolderExist = False
MsgBox "Invalid Folder Path!", vbCritical
End If
End Function
Explanation:Â If the function returns True then it is a valid folder path. If function returns False then it is invalid folder path.
What is the Usage of sheet color in Excel? When we prepare a report or a dashboard it is easy to identify or analyze reports with a change of color sheet tabs. Analysts generally give…
How to Export Access Data to Excel using VBA Code? Creating a VBA tool in MS Access is always better as compare to MS Excel. MS Access provides better user interface and ability to handle…
Introduction :- ColorIndex in Excel VBA Today let’s try to understand how ColorIndex property in Excel VBA works. It is an easy and effective way to quickly complete the development. ColorIndex property is normally used…
Learn how to write your first VBA macro in Excel to automate repetitive formatting tasks across multiple worksheets. This beginner-friendly guide will walk you through the process step-by-step, from recording your actions to customizing the code for your specific needs.
VBA Code to Find Last used Column or Row in Excel Sometimes as a developer, you need to take actions in Excel sheets based on last row or column. In Excel, there are two kinds…
VBA to Read Excel Data Using Connection String Sometimes as a programmer you need to read heavy (more then 5 MB) Excel files. There are two ways you can read data from Excel files: Open…