Excel VBA: Check If File or Folder Exists (DIR) - Open File or Create Folder
Excel VBA: Check If File or Folder Exists (DIR) - Open File or Create Folder
Excel VBA: Check If File or Folder Exists (DIR) - Open File or Create Folder
 

 
Use the DIR function in Excel VBA to check if a file or a folder exist. You can then decide what to do if they exist. For example you can open the Workbook to copy values from and then close the workbook. I will also show you how you can handle cases where the file does not exist or the file name is not typed correctly. 
 
In that case VBA generates an error but you can easily avoid with the IF statement.  [5:10​] I also show you how you can check with VBA if a folder exists. and if it doesn't exist, how you can create the folder. We use the message box function to ask the user for permission if we should create the folder or not.
 
Related Topics:

Post a Comment

Previous Post Next Post