Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Identifying whether an excel file exists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JT - 15 Nov 2007 14:20 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.