ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   IF File Exists (https://www.excelbanter.com/excel-programming/317578-if-file-exists.html)

[email protected]

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.




Lenny_821[_8_]

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



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

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