title: Python - Win32com - Open Workbook & Create a New Excel File for Each Tab
body: <p>I have an MS Excel Workbook that I would like to open and then loop through the tabs and create and save a workbook for each tab in the original workbook. So I open file A and there are tabs 1, 2, 3 and create and save a file B, C, D each with one a unique tab in it. I have the code for the VBA which creates a single copy of a worksheet but when I attempt to do this in Python I end up with all the tabs in each workbook. The following is the VBA that works:</p>
  
  <hr>
  
  <pre><code> Sub ConvertTabsToFiles()
      Dim currPath As String
      currPath = Application.ActiveWorkbook.Path
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
   For Each xWs In ThisWorkbook.Sheets
      xWs.Copy
      Application.ActiveWorkbook.SaveAs Filename:=currPath &amp; "\" &amp; xWs.Name &amp; ".xlsx"
      Application.ActiveWorkbook.Close False
   Next
     Application.DisplayAlerts = True
     Application.ScreenUpdating = True
   End Sub
  </code></pre>
  
  <hr>
  
  <p>The following is the Python Code that does not work:</p>
  
  <hr>
  
  <pre><code> xlApp = win32.com.client.Dispatch("Excel.Application")
   xlwb = xlApp.Workbooks.Open("C:\Inputfile.xlsx")
  
   for sheet in xlwb.Worksheets:
       sheet.Copy
       xlApp.ActiveWorkbook.SaveAs("C:\Users\user\AppData\Local\Temp\\"+ sheet.Name+".xlsx")
  </code></pre>
  
  <hr>
  
  <p>Your help is really appreciated, I am stumped. Thanks ahead of time.</p>