title: VBA to loop through files in subfolders
body: <p>I need to amend a column heading in multiple excel files. The files are located in subfolders two levels below the folder I want to loop through (28 .xlsx files in each folder, one folder for each Period).</p>
  
  <p>The file structure is:
  "c:\...filepath...\Period *\Daily Attributions\*.xlsx"</p>
  
  <p>I have managed to get some code to work that loops through each file in a folder but I need help to repeat the same loop for all the files in each folder. </p>
  
  <p>Here's what I have so far.</p>
  
  <pre><code>Sub FirstLast()
  '
  ' FirstLast Macro
  '
    Dim sPath As String
    Dim sFile As String
    Dim wb As Workbook
  
    sPath = "C:\...filepath...\Period 1\Daily Attributions\"
    sFile = Dir(sPath &amp; "*.xlsx")
  
  Do While sFile &lt;&gt; ""
  
  Set wb = Workbooks.Open(sPath &amp; sFile, UpdateLinks:=False)
  
      Range("E1").Select
      ActiveCell.FormulaR1C1 = "FirstLast"
      ActiveWorkbook.Save
      ActiveWindow.Close
  sFile = Dir
  
    Loop
  
  
  End Sub
  </code></pre>