Thursday, March 13, 2014

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

Excel VBA Macro to Check and Count the No.of Files and Sub Folders 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

Thanks, TAMATAM

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog