Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|