Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
IF File Exists
I am writing a macro and have run into 2 problems.
FIRST: How can I validate that a a File "MyFile" exists, and if the file does NOT exist, then exit the procedure. SECOND: if the File exists and is empty I want advise the user. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
IF File Exists
Hi Try something like this (info excel help); Set fs = Application.FileSearch With fs .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = MyFile If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With Lenny Wrote: I am writing a macro and have run into 2 problems. FIRST: How can I validate that a a File "MyFile" exists, and if the file does NOT exist, then exit the procedure. SECOND: if the File exists and is empty I want advise the user -- Lenny_82 ----------------------------------------------------------------------- Lenny_821's Profile: http://www.excelforum.com/member.php...fo&userid=1517 View this thread: http://www.excelforum.com/showthread.php?threadid=31943 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
File Exists Formula | Excel Worksheet Functions | |||
File Exists | Excel Discussion (Misc queries) | |||
File already exists | Excel Programming | |||
Save as and file exists. | Excel Programming | |||
the file already exists - do you want to replace the existing file? | Excel Programming |