[python-win32] Forcing win32com.client.dispatch to start up a freshExcel

Tom_RobbinsMilne@swissre.com Tom_RobbinsMilne at swissre.com
Tue Jun 21 18:10:53 CEST 2005


Tim,

That worked perfectly.

Much obliged.

Thanks very much,
Tom



"Tim Golden" <tim.golden at viacom-outdoor.co.uk> 

Sent by: python-win32-bounces at python.org
06/21/2005 11:52 AM




To
<python-win32 at python.org>
cc

Subject
Re: [python-win32] Forcing win32com.client.dispatch to start up a 
freshExcel






[Tom_RobbinsMilne at swissre.com]

| 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 at python.org
http://mail.python.org/mailman/listinfo/python-win32





This e-mail, including attachments, is intended for the person(s) or company named and may contain confidential and/or legally privileged information. Unauthorized disclosure, copying or use of this information may be unlawful and is prohibited. If you are not the intended recipient, please delete this message and notify the sender
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20050621/5de8fd28/attachment-0001.htm


More information about the Python-win32 mailing list