title: Get sub-folders name with files name by VBA
body: <p>I want to get <em>subfolders</em> name with files name through Excel VBA.<br>
  What I really want is <code>Column A</code> shows <em>subfolders name</em>, <code>Column B</code> shows <em>files name</em>.</p>
  
  <p>Here is my code:  </p>
  
  <pre><code>Option Explicit
  
  Private xRow As Long
  
  Sub Get_MAIN_File_Names()
      Dim fso As FileSystemObject
      Dim xDirect As String
      Dim xRootFolder As Folder
      Dim DrawingNumb As String
      Dim RevNumb As String
      Dim rootFolderStr As String
  
      Set fso = New FileSystemObject
      xRow = 0
      With Application.FileDialog(msoFileDialogFolderPicker)
         .Title = "Select Main File"
         .Show
  
         'PROCESS ROOT FOLDER
         If .SelectedItems.Count &lt;&gt; 0 Then
            xDirect = .SelectedItems(1) &amp; "\"
            Set xRootFolder = fso.GetFolder(xDirect)
            ProcessFolder fso, xRootFolder
         End If
  
      End With
  
  End Sub
  
  Private Sub ProcessFolder(fso As FileSystemObject, xFolder As Folder)
      Dim xFiles As Files
      Dim xFile As File
      Dim xSubFolders As Folders
      Dim xSubFolder As Folder
      Dim xSubFolderName As String
      Dim xFileName As String
      Dim xFileTime As String
  
      Set xFiles = xFolder.Files
      'Adding Column names
      Cells(1, "A").Value = "SubFolder Name"
      Cells(1, "B").Value = "File Name"
      Cells(1, "C").Value = "Modified Date/Time"
  
      For Each xSubFolder In xSubFolders
         xSubFolderName = xSubFolder.Name
         ActiveCell.Offset(xRow, 0) = xSubFolderName
         xRow = xRow + 1
      Next xSubFolder
  
      'LOOPS THROUGH EACH FILE NAME IN FOLDER
      For Each xFile In xFiles
  
        'EXTRACT INFORMATION FROM FILE NAME
         xFileName = xFile.Name
         xFileTime = xFile.DateLastModified
  
        'INSERT INFO INTO EXCEL
         ActiveCell.Offset(xRow, 1) = xFileName
         ActiveCell.Offset(xRow, 2) = xFileTime
         xRow = xRow + 1
      Next xFile
  
      Set xSubFolders = xFolder.SubFolders
      For Each xSubFolder In xSubFolders
          ProcessFolder fso, xSubFolder
      Next xSubFolder
  
  End Sub
  </code></pre>
  
  <p>However, I don't get what I want. I think the problem is here:  </p>
  
  <pre><code>For Each xSubFolder In xSubFolders
     xSubFolderName = xSubFolder.Name
     ActiveCell.Offset(xRow, 0) = xSubFolderName
     xRow = xRow + 1
  Next xSubFolder
  </code></pre>
  
  <p>Which part do I ignore? Or is there another way to solve?<br>
  I think the code is too long. Maybe inefficient. How to modify the code?</p>