contents of folder

M

Mark

Hi,
How display in msgbox contants (files' name in column) of
some folder?
Exist one condition: if files (in folder) is more than 2
then show msgbox with info about files.
Regards
Mark
 
B

Bernie Deitrick

Mark,

Try the macro below - change the path as needed.

HTH,
Bernie
MS Excel MVP

Sub DisplayFilesInMessageBox()
Dim myStr As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\Excel"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
If .FoundFiles.Count > 1 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
myStr = myStr & vbTab & _
.FoundFiles(i) & vbTab & _
FileDateTime(.FoundFiles(i)) & vbTab & _
FileLen(.FoundFiles(i)) & Chr(10) & Chr(10)
Next i
End If
MsgBox myStr
End If
End With
End Sub
 
M

mark

Hi Bernie!
Works Fine!
Thnx very much!
Mark
-----Original Message-----
Mark,

Try the macro below - change the path as needed.

HTH,
Bernie
MS Excel MVP

Sub DisplayFilesInMessageBox()
Dim myStr As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\Excel"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
If .FoundFiles.Count > 1 Then
MsgBox "There were " & .FoundFiles.Count & " file (s) found."
For i = 1 To .FoundFiles.Count
myStr = myStr & vbTab & _
.FoundFiles(i) & vbTab & _
FileDateTime(.FoundFiles(i)) & vbTab & _
FileLen(.FoundFiles(i)) & Chr(10) & Chr (10)
Next i
End If
MsgBox myStr
End If
End With
End Sub





.
 
Top