Thursday, 13 March 2014

How to Check and Count the No.of Files and Subfolders in a Folder

Excel VBA Macro to Check and Count the No.Of Files and Subfolders exist in a Folder

Sub Check_Count_All_SubFolders_Files()  
    Dim FromPath As String       
    Dim FSO As Object
    Dim ObjFile As Object
    Dim SourceFolder As Object
    Dim ObjSubFolder As Object
    
    Dim FileExt As String

'Application.DisplayAlerts = False
'On Error Resume Next

    FromPath = "C:\Users\Tamatam\Desktop\Tamatam\"
        
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = FSO.GetFolder(FromPath)

'< Checking whether the Folder is Empty or Not >

If (SourceFolder.Files.Count = 0) Then

  MsgBox "Source Folder is Empty"

Else

  MsgBox "The Source Folder Contains " & SourceFolder.Files.Count & " " & "Files and " & SourceFolder.Subfolders.Count & " " & "SubFolders"

End If
              

Set FSO = Nothing 'It will clean up the Object from the Memory

End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts