How can I use VBA in Excel to determine if a file with a known name exists in a known directory?
How can I use VBA in Excel to determine if a file with a known name exists in a known directory?
Last edited by Ron Coderre; 10-29-2008 at 12:55 PM.
Function FileExists(sPath As String, sFile As String) As Boolean Static sPS As String If Len(sPS) = 0 Then sPS = Application.PathSeparator FileExists = Len(Dir(sPath & IIf(Right(sPath, 1) = sPS, "", sPS) & sFile)) > 0 End Function
Last edited by shg; 10-28-2008 at 01:03 PM.
Entia non sunt multiplicanda sine necessitate
I found that I can also use
Dir ("Full path name")
If this is the null string, the file does not exist. If the file does exist, Dir will equal the name of the file.
Sure. The LEN function is faster, but the result is the same.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks