blossomthe2nd
Active Member
- Joined
- Oct 11, 2010
- Messages
- 450
Hi Guys
I have a found Code that will count files in a folder - I wish to count XLS files in this folder S:\Business Support\CGB\CGB\Jav\Jav Templates Received
Can anyone advise how to amend this query ?
Thanks
I have a found Code that will count files in a folder - I wish to count XLS files in this folder S:\Business Support\CGB\CGB\Jav\Jav Templates Received
Can anyone advise how to amend this query ?
Thanks
HTML:
Private Function CountFiles(strDirectory As String, Optional strExt As String = "*.*") As Double
'Author : Ken Puls (www.excelguru.ca)
'Function purpose: To count files in a directory. If a file extension is provided,
' then count only files of that type, otherwise return a count of all files.
Dim objFso As Object
Dim objFiles As Object
Dim objFile As Object
'Set Error Handling
On Error GoTo EarlyExit
'Create objects to get a count of files in the directory
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(strDirectory).Files
'Count files (that match the extension if provided)
If strExt = "*.*" Then
CountFiles = objFiles.Count
Else
For Each objFile In objFiles
If UCase(Right(objFile.Path, (Len(objFile.Path) - InStrRev(objFile.Path, ".")))) = UCase(strExt) Then
CountFiles = CountFiles + 1
End If
Next objFile
End If
EarlyExit:
'Clean up
On Error Resume Next
Set objFile = Nothing
Set objFiles = Nothing
Set objFso = Nothing
On Error GoTo 0
End Function