Thursday, 13 March 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
           (Analyst)

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts