A resource for users and developers of Microsoft Excel |
|||||||||
| Email us your FAQ suggestion. |
|||||||||
Visit often ! Pages are updated daily. |
|||||||||
This is the Excel "How to" Frequently Asked Questions page |
|||||||||
Answers to Frequently Asked Questions about how to do common tasks in Microsoft Excel. |
|||||||||
Excel "How to" FAQs |
| How to verify if a certain workbook exists? |
| VBA |
When verifying if a certain workbook name exists, you would also want to verify if the source path and folder to which it supposedly belongs also exists. It is possible for the workbook to exist outside the source folder where the user thinks it should be, and it is possible the source folder path exists but the workbook is not even on that computer. As a service to your users, let them know if the path does not exist and what to do about it, and let them know if the workbook itself is not in the source folder. To do that, two separate If structures are set up to evaluate the source folder path, and then the existence of the workbook in that folder. A Message Box informs the user if either the path or workbook are not found, and what steps they should take. Sub VerifyFolderAndFile() 'Declare and define variables. 'Verify existence of the source path. 'Verify there really is a file named "YourWorkbookName.xls" in the path "C:\Your\File\Path\" 'At this point, the source path and source file names are all found and the macro can continue. End Sub
|