VBA Code: IsFile — Does a file exist?

Here is some code to determine if a file exists.  Requires reference to Microsoft Scripting Runtime.  (Error handling is commented out).

Function IsFile(sFileName) As Boolean
‘Purpose: Checks for the existence of a file based on path/name passed in.

‘CalledFrom: many
‘Calls: basErrorHandler.ErrorHandler(), basDeclares.adh_accFileExists()
‘Assumes: na
‘Returns: True/False indicating True = Yes False = No.

‘Test for the existance of a file
‘Must include full path in sFileName
On Error GoTo ErrorHandling
Dim fs As Object

Set fs = CreateObject(“Scripting.FileSystemObject”)

If fs.FileExists(sFileName) Then
     IsFile = True
     IsFile = False
End If

Exit Function

‘ Call ErrorHandler(“basUtils.IsFile”, Err.Number, Err.Description)
GoTo ExitProc

End Function

This entry was posted in VBA Code and tagged . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s