Create another Excel instance

yvan yvan_charpentier at hotmail.com
Fri Jul 11 15:59:07 EDT 2003


"Cy Edmunds" <cedmunds at spamless.rochester.rr.com> wrote in message news:<FZmPa.28943$EQ5.7055 at twister.nyroc.rr.com>...
> "yvan" <yvan_charpentier at hotmail.com> wrote in message
> news:9ee55987.0307101339.701965a7 at posting.google.com...
> > I am using Excel to save data.
> > Everything works as i intend it to if no other instance of Excel is
>  running.
> > If another instance is running, it will do the job, but also close that
>  instance.
> > How can i prevent that from happening?
> >
> > Here is the code that creates and deletes the instance:
> > class CExcel:
> >     def __init__(self, bVisible = 0):
> >         import sys
> >         import pythoncom
> >         sys.coinit_flags = 0
> >         pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
> >         import win32com.client.dynamic
> >         self.xlApp = win32com.client.dynamic.Dispatch("Excel.Application")
> >         self.xlApp.Visible = bVisible
> >         self.xlBook = self.xlApp.Workbooks.Add()
> >         self.xlSheet = self.xlApp.ActiveSheet
> >
> >     def __del__(self):
> >         import pythoncom
> >         if self.xlSheet != None:
> >             del(self.xlSheet)
> >         if self.xlBook != None:
> >             self.xlBook.Close(0)
> >             del(self.xlBook)
> >         if self.xlApp != None:
> >             self.xlApp.Quit()
> >             del(self.xlApp)
> >         pythoncom.CoUninitialize()
> >
> > Thank for your help,
> >
> > -Yvan
> 
> I haven't tried this myself but maybe...
> 
> if self.xlApp != None:
>     nbook = self.xlApp.Workbooks.Count # number of open workbooks
>     if nbook == 0:
>         self.xlApp.Quit()
> 
> Let us know how you made out.

It looks like that would work if 'Visible' was set to 1. Unfortunately
mine has to be 0. Thanks for the suggestion.
Basically, my problem is that the object uses the same process if an
instance of Excel already exists.
How can i create the new instance in a different process?




More information about the Python-list mailing list