I am trying to loop through a bunch of excel files and copy a specific sheet from each of them into another excel file:
for ii in ll_files:
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb_1 = excel.Workbooks.Open(ii)
ws_1 = wb_1.Worksheets('Q1')
wb_2 = excel.Workbooks.Open(r'filepath')
ws_2 = wb_2.Worksheets('answers')
ws_1.Copy(ws_2)
wb_1.Save()
wb_2.Save()
wb_1.Close(True)
wb_2.Close(True)
excel.Application.Quit()
print ii
time.sleep(1)
Works on about half the files I'm looping through, while the other half fail with this error:
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Excel', u'Copy method of Worksheet class failed', u'xlmain11.chm', 0, -2146827284), None)
All of the files have a 'Q1' tab