ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Identifying whether an excel file exists (https://www.excelbanter.com/excel-programming/401162-identifying-whether-excel-file-exists.html)

JT[_8_]

Identifying whether an excel file exists
 
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

Identifying whether an excel file exists
 
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,
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


"JT" wrote:

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


Charles Chickering

Identifying whether an excel file exists
 
JT, try this

len(dir("C:\Test.txt")) 0

Substitute your file for "C:\Test.txt"

--
Charles Chickering

"A good example is twice the value of good advice."


"JT" wrote:

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


Gary''s Student

Identifying whether an excel file exists
 
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
--
Gary''s Student - gsnu200756


"JT" wrote:

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


Frederik[_3_]

Identifying whether an excel file exists
 
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!

"JT" schreef in bericht
...
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




JT[_8_]

Identifying whether an excel file exists
 
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.


All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com