ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is it there? (https://www.excelbanter.com/excel-programming/356862-there.html)

MD

Is it there?
 
Good day all,

I'm looking for a simple code that checks if a file exists in a folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD





Steve Yandl

Is it there?
 
Sub CheckExistFile()
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTestPath = "c:\temp\abc.txt "
If objFSO.FileExists(strTestPath) Then
MsgBox "Yes it exists"
Else
MsgBox "Sorry, it doesn't exist"
End If
End Sub

Steve Yandl



"MD" wrote in message
.. .
Good day all,

I'm looking for a simple code that checks if a file exists in a folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD







MD

Is it there?
 
Thanks Steve....

FYI this was my version... I was just looking for something that could of
been a one liner!!! LOL
Dim MyCheckFile As String, MyTest
MyCheckFile = c:\temp\abc.txt"
MyTest = GetAttr(MyCheckFile)
GoTo continue
version:
MsgBox ("Sorry, it doesn't exist")
Exit Sub

continue:



"Steve Yandl" wrote in message
...
Sub CheckExistFile()
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTestPath = "c:\temp\abc.txt "
If objFSO.FileExists(strTestPath) Then
MsgBox "Yes it exists"
Else
MsgBox "Sorry, it doesn't exist"
End If
End Sub

Steve Yandl



"MD" wrote in message
.. .
Good day all,

I'm looking for a simple code that checks if a file exists in a folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD









Greg Wilson

Is it there?
 
See John Walkenbach's FileExists function:

http://j-walk.com/ss/excel/tips/tip54.htm#func1

"MD" wrote:

Good day all,

I'm looking for a simple code that checks if a file exists in a folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD






Randy Harmelink

Is it there?
 
I was just looking for something that could of been a one liner!!! <<

All you had to do was do a google search on:

excel vba file exist


....and you would have found a one-line solution on the first entry...


AA2e72E

Is it there?
 
Have a look at the PathFileExists API call; it can verify the existence of
paths as well as files.

"MD" wrote:

Good day all,

I'm looking for a simple code that checks if a file exists in a folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD






Chip Pearson

Is it there?
 
Use the Dir function.

Dim FName As String
FName = "H:\Test\Book1.xls"
If Dir(FName) = "" Then
Debug.Print "does not exist"
Else
Debug.Print "File exists"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"MD" wrote in message
.. .
Good day all,

I'm looking for a simple code that checks if a file exists in a
folder.

if c:\temp\abc.txt is there then
else exit sub

Regards

MD








All times are GMT +1. The time now is 04:50 AM.

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