Excel VBA – Check if workbook exists…

This is a function to verify if your workbook exists in the defined location, so that before you can open your workbook, VBA codes can open your desired workbook properly.

It will return “TRUE” if the workbook is located in the desired location.

It will return “FALSE” if the workbook doesn’t exist in the desired location.

Function DoesWorkBookExist(ByVal wbPath As String, ByVal WBName As String) As Boolean

Dim i As Integer
Dim FileCheck As String

FileCheck = wbPath & “\” & WBName

If Dir(FileCheck) <> “” Then
‘MsgBox (“Workbook – ” & wbName & ” exists”)
DoesWorkBookExist = True
Else
‘MsgBox (“Workbook – ” & wbName & ” doesn’t exist”)
DoesWorkBookExist = False
End If

End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s