» Determine if a workbook exists using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
Function FileExists(FullFileName As String) As Boolean
' returns TRUE if the file exists
FileExists = Len(Dir(FullFileName)) > 0
End Function
Example:
If Not FileExists("C:\FolderName\SubFolder\FileName.xls") Then
MsgBox "The file doesn't exist!"
Else
Workbooks.Open "C:\FolderName\SubFolder\FileName.xls"
End If
Book Store:
Recommended Books:
- Investments + S&P Card + Powerweb + StockTrak discount coupon
- East of Eden (Oprah's Book Club)
- Excel Charts
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Windows XP All-in-One Desk Reference For Dummies
- Investing for Dummies, Third Edition


If Len(Dir(FileName)) > 0 And FileName <> "" Then
FileExists = True
Else: FileExists = False
End If