Python crash when trying to generate an Excel worksheet with VBA macros

dan_roman dan_roman_sb at
Wed Oct 4 12:53:47 CEST 2006

I developed a script with a nice interface in Tkinter that allows me to
edit some formulas and to generate an Excel worksheet with VBA macros
within it. The script runs perfectlly in Office 2000, but in Office
2003 crash at line: "wbc = workbook.VBProject.VBComponents.Add(1)"
Please help me :-(

the code of the module that crash is (only in Excel 2003, in 2000 not):

import os
import string
from win32com.client import Dispatch, constants

Dim nrfunc As Integer
Dim cursor As Integer
Dim i As Integer
Dim j As Integer

Sub Fill()

'Aflu numaru de functii din XL
i = 1
def createExcelReport(projectName,templateName,saveToPath):
	# acquire application object, which may start application
	application = Dispatch("Excel.Application")

	# create new file ('Workbook' in Excel-vocabulary) using the specified
	workbook = application.Workbooks.Add("Template1.xls")

	# store default worksheet object so we can delete it later
	defaultWorksheet = workbook.Worksheets(1)

	worksheet1 = workbook.Worksheets(1)
	worksheet2 = workbook.Worksheets(2)
	worksheet3 = workbook.Worksheets(3)

---->>>>>	wbc = workbook.VBProject.VBComponents.Add(1) <<<<------ here
is the problem





	worksheet1 = workbook.Worksheets(1)

	# make stuff visible now.
	application.Visible = True

More information about the Python-list mailing list