title: How to merge multiple XLSX files into one Workbook while keeping their worksheets separate?
body: <p>I'm trying to merge all .xlsx files within a folder into one workbook while keeping their worksheets separated. My code below is grabbing specified files, merging them into one workbook but only copying the first worksheet from each file instead of all their worksheets.</p>
  <p>My output file is currently one workbook containing the first worksheet of each merged file but some files have multiple worksheets. Would anyone know how I can grab all worksheets from multiple files and combine them into one workbook?</p>
  <p>Thanks for your time!</p>
  <pre><code>import win32com.client as win32
  import os
  
  excel = win32.gencache.EnsureDispatch('Excel.Application')
  wb = excel.Workbooks.Add()
  
  path = r'C:\Users\Desktop\merge'
  files = os.listdir(path)
  
  for f in [os.path.join(os.getcwd(), &quot;Daily Pipeline&quot;), os.path.join(os.getcwd(), &quot;Loans&quot;)]: 
      w = excel.Workbooks.Open(f) 
      w.Sheets(1).Copy(wb.Sheets(1))
  
  
  wb.SaveAs(os.path.join(os.getcwd(), &quot;Final.xlsx&quot;))
  excel.Application.Quit()
  </code></pre>