How can a make a formula that gives me the "count" of
files in a Folder?
If it ins´t possible in a formula can i make a macro that
gives me this "Count" in a cell? how?
Thanks a lot
SpeeD72
Sub filescount()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\a"
.SearchSubFolders = True
.Filename = "*.*"
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
End Sub
"SpeeD72" <the_kid...@hotmail.com> wrote in message
news:02b801c37886$1de280c0$a101...@phx.gbl...
Here's a simple little function to do it
Function FileCount(FolderName As String, _
Optional FileFilter As String = "*", _
Optional FileType As MsoFileType =
msoFileTypeAllFiles) As Long
With Application.FileSearch
.NewSearch
.LookIn = FolderName
.SearchSubFolders = False ' True to include subfolders
.Filename = FileFilter
.MatchTextExactly = True
.FileType = FileType
.Execute
FileCount = .FoundFiles.Count
End With
End Function
Call it like
x = FileCount ("C:\MyTest"
for all file types, or
x = FileCount("C:\myTest",,msoFileTypeExcelWorkbooks)
just for Excel workbooks
--
HTH
Bob Phillips
"SpeeD72" <the_kid...@hotmail.com> wrote in message
news:02b801c37886$1de280c0$a101...@phx.gbl...
Thanks a lot. But, if instead of the message Box the
value "returns" to a cell, how would the programing Be?
Thank´s a lot!!
SpeeD
>.
>
"SpeeD72" <the_kid...@hotmail.com> wrote in message
news:037301c3788e$505f2e10$a101...@phx.gbl...
Hi Don.
Thanks a lot. But, if instead of the message Box the
value "returns" to a cell, how would the programing Be?
Thank愀 a lot!!
SpeeD
>If it ins愒 possible in a formula can i make a macro that