Hello group!
I have a (hopefully) quick query. Can anybody help?
I am writing a procedure and require a function which reads a file
path string and returns true or false depending on whether the file
exists on the user's computer. Does anybody out there know how this
can be achieved?
Thanks in advance.
John
Pranav Vaidya - 15 Nov 2007 14:33 GMT
Hi JT,
Before you use the below funtion, you have to get a reference to 'Microsoft
Scripting Runtime'
Function CheckFile() As Boolean
Dim mFile As FileSystemObject
Set mFile = New FileSystemObject
CheckFile = mFile.FileExists("C:\test\test.xls")
End Function
In the above function you can type your path or change the function to suit
your requirements.
HTH,

Signature
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!
> Hello group!
>
[quoted text clipped - 8 lines]
>
> John
Charles Chickering - 15 Nov 2007 14:34 GMT
JT, try this
len(dir("C:\Test.txt")) > 0
Substitute your file for "C:\Test.txt"

Signature
Charles Chickering
"A good example is twice the value of good advice."
> Hello group!
>
[quoted text clipped - 8 lines]
>
> John
Gary''s Student - 15 Nov 2007 14:37 GMT
Sub test()
If Dir("C:\Data\test.xls") <> "" Then
MsgBox "Exist"
Else
MsgBox "Not exist"
End If
End Sub
Just re-cast it as a Boolean function

Signature
Gary''s Student - gsnu200756
> Hello group!
>
[quoted text clipped - 8 lines]
>
> John
Frederik - 15 Nov 2007 15:53 GMT
Hello JT
Have a look at:
http://www.j-walk.com/ss/excel/tips/tip54.htm
I learned a lot from J. Walkenbachs site!!!
Enjoy!
> Hello group!
>
[quoted text clipped - 8 lines]
>
> John
JT - 16 Nov 2007 12:41 GMT
Thanks to all of you, that was really helpful.
John Walkenbach wrote the Excel VBA for dummies book and I'm a fan of
his work.