When I use win32.com to open an excel file and paste the sheet into another excel file i get a copy paste error.
import win32com.client
import os
excel = win32com.client.Dispatch("Excel.Application")
w = excel.Workbooks.Open(os.path.join(os.getcwd(), "my_excel_file.xlsx"))
w.Sheets.Copy(wb.Sheets(1))
wb.SaveAs(os.path.join(os.getcwd(), "new_excel_file.xlsx"))
excel.Application.Quit()
This is the error I get:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workbook. To move or copy the data to the destination workbook, you can select the data, and then use the Copy and Paste commands to insert it into the sheets of another workbook.', 'xlmain11.chm', 0, -2146827284), None)