Count Files

Count files (including subfolders)
copy all 3 sections into one module

Option Explicit
Dim objFSO As Object
Dim objFile As Object, objFiles As Object
Dim objSubFolder As Object, objSubFolders As Object
Dim FileCount As Double
Sub CountFiles()
FileCount = 0
Dim StartFolder As String
Dim flDlg As FileDialog
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set flDlg = Application.FileDialog(msoFileDialogFolderPicker)
flDlg.InitialFileName = Application.DefaultFilePath & "\"
If flDlg.Show = False Then Exit Sub
StartFolder = flDlg.SelectedItems(1)
If Right(StartFolder, 1) <> "\" Then StartFolder = StartFolder & "\"
Call Recursive_CountFiles(StartFolder)
Set objFSO = Nothing
Application.StatusBar = ""
MsgBox FileCount & " files found in " & """" & StartFolder & """"
End Sub
Sub Recursive_CountFiles(strFolder As String)
On Error GoTo ErrorFound
Set objFiles = objFSO.GetFolder(strFolder).Files
Set objSubFolders = objFSO.GetFolder(strFolder).Subfolders
For Each objFile In objFiles
FileCount = FileCount + 1
Application.StatusBar = "Counting files, please wait... | " & FileCount
DoEvents
Next objFile
Set objFiles = Nothing
For Each objSubFolder In objSubFolders
Call Recursive_CountFiles(objSubFolder.Path)
Next objSubFolder
Set objSubFolders = Nothing
Exit Sub
ErrorFound:
MsgBox Err.Description
On Error Resume Next
On Error GoTo 0
End Sub