[python-win32] com_error when creating excel sheet

Graham Bloice graham.bloice at trihedral.com
Tue Aug 10 16:24:45 CEST 2004


> Hi,
>
> The following script results in the error listed below:
>
> import win32com.client
> from win32com.client import Dispatch
> x1App = Dispatch("Excel.Application")
> x1App.Visible=1
> x1App.Workbooks.Add()
> x1Sheet=x1App.Sheets(1)
> x1Sheet.Name="Sheet 1"
> x2Sheet = x1App.Sheets(2)
> x2Sheet.Name = "Sheeet 2"
> x3Sheet = x1App.Sheets(3)
> x3Sheet.Name="Sheet 3"
>
> Traceback... line 8, in ? x2Sheet = x1App.Sheets(2)
> ...
> com_error: (-2147352567, 'Exception occurred.', (0. None, None,
> None, 0, -2147352565), None)
>
> Running Python 2.3.3 on XP. Excel 2002 installed.
>
> Does anybody know what the solution to the problem is?
>

Might it be that your copy of excel is configured so that there is only 1
sheet in a new workbook.  See Tools | Options | General | Sheets in new
workbook.

Regards,

Graham Bloice



More information about the Python-win32 mailing list