View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Check Folder For Files

Dave,

Paste this code in and it does it for the named fole File1.xls. To loop
through several files and check for their existence you could put the names
to search for an a worksheets and loop through that. If you stuck in doing
that post back.


Sub MACRO()
MsgBox ("Select the Folder")
Set foldername1 = Application.FileDialog(msoFileDialogFolderPicker)
foldername1.Show
foldername1path = CurDir()
If Dir(foldername1path & "book1.xls") < "" Then
MsgBox "File exists"
Else
MsgBox "File does not exist"
End If
End Sub

Mike

"Dave" wrote:

Hi Guys,

I'd like to do the following in a macro:

Sub MACRO()

MsgBox ("Select the Folder")
Set foldername1 = Application.FileDialog(msoFileDialogFolderPicker)
foldername1.Show
foldername1path = CurDir()

'HELP HERE

End Sub

I want to then check the folder for files:

file1.xls
file245.xls
file278.xls
file88.xls

etc.

so they'll be something like foldername1path & "\" file1.xls (AM I RIGHT?)

If one or more of these files do not exist, I would like a MsbBox to show
with something like "File1.xls and File88.xls not found".

Thanks in advance
Dave