Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MD MD is offline
external usenet poster
 
Posts: 9
Default 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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default 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






  #3   Report Post  
Posted to microsoft.public.excel.programming
MD MD is offline
external usenet poster
 
Posts: 9
Default 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








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default 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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default 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...



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"