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


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Exists Formula El Bee Excel Worksheet Functions 4 November 9th 06 03:45 PM
File Exists Mike McLellan Excel Discussion (Misc queries) 2 May 4th 06 09:20 AM
File already exists Michael Malinsky[_3_] Excel Programming 0 June 28th 04 08:02 PM
Save as and file exists. Barry Excel Programming 1 June 1st 04 12:05 AM
the file already exists - do you want to replace the existing file? Paul James[_3_] Excel Programming 4 December 12th 03 02:50 AM


All times are GMT +1. The time now is 10:22 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"