Check Folder For Files
Try this out, i built it as a function and put a test to it, you just need to
pass in the filenames in a loop and if it does not exist it will add it to a
string
Dim mystring As String
Function checkForFiles(filename)
Dim mystring As String
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object
MsgBox ("Select the Folder")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set foldername1 = Application.FileDialog(msoFileDialogFolderPicker)
foldername1.Show
foldername1path = CurDir()
'MsgBox oFSO.fileexists(foldername1path & "\" & filename)
If oFSO.fileexists(foldername1path & "\" & filename) = "False" Then
checkForFiles = filename
End Function
Sub main()
Dim myReturn As String
myReturn = checkForFiles("book1.xls")
If myReturn < "" Then mystring = mystring & myReturn
MsgBox mystring
End Sub
--
-John
Please rate when your question is answered to help us and others know what
is helpful.
"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
|