Thursday, March 13, 2014

How to List all the Sub Folders and Files Names in the Message Box

Excel VBA Macro to Display all the Sub Folders and Files Names in the Message Box
Sub List_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\MyFolder\"
        
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = FSO.GetFolder(FromPath)
              
'<Loop through to list all subfolders in a folder path >              
For Each ObjSubFolder In SourceFolder.SubFolders    
    MsgBox ObjSubFolder.Name    
Next ObjSubFolder

'<Loop through to list all files in a folder path >
For Each ObjFile In SourceFolder.Files    
    MsgBox ObjFile.Name    
Next ObjFile

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.