Make Excel check for an external file

  • Thread starter Thread starter Alexander Schek
  • Start date Start date
A

Alexander Schek

Hi,
In A1 I have a path to an image on my Hard Drive.. let's say
"c:\images\image1.jpg"
Is there any formula that would say YES or NO as a result if the image
(file) actually exist on the folder?
If so, how could I address this need ?
Thanks a lot!

Alex
 
Alexander,

Public Function FileExists(FileName As String) As Boolean
' Simple function from Dana DeLouis to check if a file exists
FileExists = Len(Dir(FileName))
End Function

An example of how it's used in VBA:

Private Sub ExternalFilesExist()
dLetter = Left(ThisWorkbook.Path, 3)
fPath = "yourpath" & "\"
If FileExists(dLetter & fPath & yourfilename") = True Then
' File Exists
Else
' File doesn't exist
End If
End Sub

Modify the above to suit.

John
 
Back
Top