Sub listFiles()
Dim filesToProcess As Long
Dim myPath As String
myPath = "C:\ViewPoint\"
'Use the Filesearch Object
With Application.FileSearch
.NewSearch
.LookIn = myPath
.SearchSubFolders = False
.Filename = "*.*"
.Execute
Worksheets("Sum").Range("B3").Value = .FoundFiles.Count
End With
End Sub
Public Sub Demo()
MsgBox CountFiles("C:\ViewPoint\", "*.xls")
End Sub
Function CountFiles(tgtDir As String, Extention As String)
Dim fName As String
Dim cnt As Integer
fName = Dir(tgtDir)
cnt = 0
Do While fName <> ""
If fName <> "." And _
fName <> ".." And _
fName Like Extention Then
cnt = cnt + 1
End If
fName = Dir()
Loop
CountFiles = cnt
End Function
Sub FileCount()
Dim fsoObj As Object '// Scripting.FileSystemObject
Dim fsoMapp As Object '// Scripting.Folder
Set fsoObj = CreateObject("Scripting.FileSystemObject")
Set fsoMapp = fsoObj.GetFolder("C:\ExcelFiles\Useful")
MsgBox fsoMapp.Files.Count
Set fsoObj = Nothing
Set fsoMapp = Nothing
End Sub