I have an Excel macro that deletes a sheet, copies another sheet and renames it to the same name of the deleted sheet. This works fine when run from Excel, but when I run it by calling the macro from Python I get the following error message:
' Run-time error '1004': Cannot rename a sheet to the same name as another sheet, a referenced object library or a workbook referenced by VisualBasic. '
The macro has code like the following:
Sheets("CC").Delete ActiveWindow.View = xlPageBreakPreview Sheets("FY").Copy After:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = "CC"
and the debugger highlights the error on the last line where the sheet is renamed. I've also tried putting these calls directly in python but get the same error message.
Any suggestions are much appreciated!