[EMAIL PROTECTED]

| I'm trying to use Python's win32com interface to drive an excel spreadsheet. 

| I've managed to have it open the sheet, call a VBA function with arguments, 
and close it down cleanly. 

| However, if Excel is already running, it closes the open instance. Which is 
not good. 

| Is there a way I can do the equivalent of VBA's CreateObject() with win32com? 
I have purchased 
| "Python Programming on | Win32", and can't find anything. 

I'm not sure about the CreateObject bit, not being a
VBA person, but I suspect you may want to use the
DispatchEx method rather than simply Dispatch. eg,

[some spreadsheet already open]

<code>
import win32com.client

xl = win32com.client.DispatchEx ("Excel.Application")
wb = xl.Workbooks.Add ()
ws = xl.ActiveSheet

ws.Cells (1, 1).Value = "Hello"

wb.SaveAs ("c:/temp/temp.xls")
wb.Close ()
xl.Quit ()

xl = None
</code>

[original spreadsheet still open]

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to