[python-win32] com_error when creating excel sheet

Tim Roberts timr at probo.com
Tue Aug 10 18:34:22 CEST 2004


On Mon, 09 Aug 2004 22:28:45 +0200, "Sandra Herman" <s_herman at web.de> wrote:

>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?
>  
>

Well, I just cut-and-pasted your exact script here, and it worked 
perfectly with Python 2.3 and Excel 2003.

Based on the error message, is it possible your default workbook does 
not start out with three sheets?  Have you tried, for example, something 
like this:
    ...
    x1App.Sheets.Add()
    x2Sheet = x1App.Sheets(2)

-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list