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_flag s = 0
pythoncom.CoIni tializeEx(pytho ncom.COINIT_MUL TITHREADED)
import win32com.client .dynamic
self.xlApp = win32com.client .dynamic.Dispat ch("Excel.Appli cation")
self.xlApp.Visi ble = bVisible
self.xlBook = self.xlApp.Work books.Add()
self.xlSheet = self.xlApp.Acti veSheet
def __del__(self):
import pythoncom
if self.xlSheet != None:
del(self.xlShee t)
if self.xlBook != None:
self.xlBook.Clo se(0)
del(self.xlBook )
if self.xlApp != None:
self.xlApp.Quit ()
del(self.xlApp)
pythoncom.CoUni nitialize()
Thank for your help,
-Yvan
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_flag s = 0
pythoncom.CoIni tializeEx(pytho ncom.COINIT_MUL TITHREADED)
import win32com.client .dynamic
self.xlApp = win32com.client .dynamic.Dispat ch("Excel.Appli cation")
self.xlApp.Visi ble = bVisible
self.xlBook = self.xlApp.Work books.Add()
self.xlSheet = self.xlApp.Acti veSheet
def __del__(self):
import pythoncom
if self.xlSheet != None:
del(self.xlShee t)
if self.xlBook != None:
self.xlBook.Clo se(0)
del(self.xlBook )
if self.xlApp != None:
self.xlApp.Quit ()
del(self.xlApp)
pythoncom.CoUni nitialize()
Thank for your help,
-Yvan
Comment