OzGrid

Excel VBA: Does Workbook Exist

< Back to Search results

 Category: [Excel]  Demo Available 

Excel VBA: Does Workbook Exist

 

Got any Excel/VBA Questions? Free Excel Help.

This UDF will return True Or False depending on whether the specified Excel Workbook exists or not.

The VBA Code

Function WorkBookExist(FilePathName As String) As Boolean
Dim strCheck As String
'''''''''''''''''''''''''''''''

'Written by www.Ozgrid.com

'Test to see if a Workbook exists

''''''''''''''''''''''''''''''''
strCheck = Dir(FilePathName)


WorkBookExist = Not strCheck = vbNullString

End Function

To use this UDF push Alt+F11 and go Insert>Module and paste in the code. Push Alt+Q and save. The Function will appear under "User Defined" in the Paste Function dialog box (Shift+F3). 

Enter the function like this.

=WorkBookExist("C:\OzGrid Likom\Testings\Book2.xls")

OR

=IF(WorkBookExist("C:\OzGrid Likom\Testings\Book2.xls"),

"Do True Statement","Else Do False Statement")

Where you replace Do True Statement with the Excel Function to perform if True and Else Do False Statement with the Excel Function to perform if False.

 

See also:

Matching ComboBox Controls
Adding a Description and Category to your User Defined Functions in Excel
Excel VBA: Disable Cut/Copy in Excel Workbooks

 

Free Training Course: Lesson 1 - Excel Fundamentals

 

See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)