title: VBA code to loop through files in a folder
body: <p>I am looking for a way to automate the process of opening 1300 separate Excel files in separate subfolders and making the same change in each file. The change will be to the same cell on the same tab of each file. I'm Almost done with the code just having problems with Workbook.open and making sure its selecting the correct excel files. I have my code listed below. I also have some more information if you need it. Thanks for the help!</p>
  <p>The Excel Files i need to access are in sub folders in a parent folder/
  The Excel files that need to be updated all end in the List.xlsx</p>
  <pre><code>Sub LoopFilesInFolder()
  Dim folderName As String
  Dim FSOLibrary As FileSystemObject
  Dim FSOFolder As Object
  Dim FSOFile As Object
  
  'Set the file name to a variable
  folderName = &quot;\\net\fs1\users\alex.wood\Desktop\TC Excel Test and Creation Files\VBA TEST FOLDER&quot;
  
  'Set all the references to the FSO Library
  Set FSOLibrary = New FileSystemObject
  Set FSOFolder = FSOLibrary.GetFolder(folderName)
  Set FSOFile = FSOFolder.Files
  
  'Use For Each loop to loop through each file in the folder
  For Each FSOFile In FSOFile
      Workbooks.Open Filename:=Dir(&quot;\\net\fs1\users\alex.wood\Desktop\TC Excel Test and Creation Files\VBA TEST FOLDER\*list*&quot;)
  
      Range(&quot;G1&quot;).Select
      ActiveCell.FormulaR1C1 = &quot;New Thin Client&quot;
      ActiveWorkbook.Save
      ActiveWindow.Close
  
  Next
  
  'Release the memory
  Set FSOLibrary = Nothing
  Set FSOFolder = Nothing
  Set FSOFile = Nothing
  
  End Sub
  </code></pre>