View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Check if file exists

Here is a 1 instructtion VBA function that you can use.
Install as follows from speadsheet menu

1) from spreadsheet: Tools - Macro - Visual Basic Editor
2) from VBA: Insert - Module
3) Copy code below and paste into VBA window
4) Add code to cell: =ifexist("C:\abc.xls")
You can use any string or cell reference. The code will work with wildcards
as well.


Function will return the filename if it exists or "" if file is not found.
=if(ifexist("C:\abc.xls")= "","File Not found","File Found")


Function ifexist(Target As String) As String
ifexists = Dir(Target)
End Function

"Jon" wrote:

Is there an easy way in Excel to check if a file exists? I can concatenate
strings and build the full path and name of the file I want to check. I will
have a few hundred file names in column A, and in column B I just want to
have a formula that equals "Yes" if the file exists on my LAN or "No" if it
doesn't.

I can't seem to find a way to do it with Excel formulas. I'm sure this is
trivial in VBA, but I don't know it.

Thanks.