Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Count files in a Folder!

0 views
Skip to first unread message

SpeeD72

unread,
Sep 11, 2003, 12:59:51 PM9/11/03
to
Hi guys.

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

Don Guillett

unread,
Sep 11, 2003, 1:25:59 PM9/11/03
to
try this

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...

Bob Phillips

unread,
Sep 11, 2003, 1:38:18 PM9/11/03
to
Speed,

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...

SpeeD72

unread,
Sep 11, 2003, 1:58:32 PM9/11/03
to
Hi Don.

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

>.
>

Don Guillett

unread,
Sep 11, 2003, 2:18:25 PM9/11/03
to
> MsgBox "There were " & .FoundFiles.Count & _
> " file(s) found."
range("a1")=.foundfiles.count

"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

0 new messages