Neil,
Here is a simple UDF.
Function FileCount(FolderName As String, _
Optional FileFilter As String = "*", _
Optional FileTypes As Long = 1, _
Optional SubFolders As Boolean = False) As Long
With Application.FileSearch
.NewSearch
.LookIn = FolderName
.SearchSubFolders = SubFolders
.Filename = FileFilter
.MatchTextExactly = True
.FileType = FileTypes
.Execute
FileCount = .FoundFiles.Count
End With
End Function
Use like so
FileCount("C:\myTest") - all files in a directory
FileCount("C:\myTest",,,True) - all files in a directory, including
subfolders
FileCount("C:\myTest","Test") - all files in a directory with 'test' in the
name
FileCount("C:\myTest",,4) - all Excel workbooks in a directory
This can be called from a worksheet or VBA, VBA has the advantage of
allowing the msoFileType Enum for file types.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)