<p>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:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>The macro has code like the following:</p>

<pre><code>Sheets("CC").Delete
ActiveWindow.View = xlPageBreakPreview
Sheets("FY").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "CC"
</code></pre>

<p>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.</p>

<p>Any suggestions are much appreciated!</p>

<p>Thanks.</p>

I ran the code inside Excel VBA.
I am guessing that the following line is failing.
```
Sheets("CC").Delete
```
And that is the reason, you can't give the new sheet same name as existing (non-deleted) sheet.
Put
```
Application.DisplayAlerts = False
```
before
```
Sheets("CC").Delete
```
and
```
Application.DisplayAlerts = True
```
once you are finished with the code.
I haven't used python but it seems the library is swallowing that error for you and letting you go ahead to the next statement.
Hope that helps.