从Python运行Excelmacros(但Excel进程保留在内存中)

用下面的python方法,我调用了一个Excelmacros。 当我得到这个工作时,我很高兴,但是我想知道每当我执行这个时,我可以看到一个Windows临时/locking文件与我使用macros从.XLA同名。

class XlaMakeUnmake: __configFile = 'xla_svn.cfg' __vbaTools = 'makeProtected.xla' __entries = {} def __init__(self): self.__readConfig() def __newDirs(self, dir): try: os.makedirs(dir) except OSError, e: if e.errno != errno.EEXIST: raise ### WILL ONLY WORK FOR UNPROTECTED ''' filePath: path of XLA to unmake outputDir: folder in which the lightweight xla and its components will be pushed to ''' def unmake(self, filePath, outputDir): xl = win32com.client.Dispatch("Excel.Application") xl.Visible = 0 self.__newDirs(outputDir) xl.Application.Run("'" + os.getcwd() + os.sep + self.__vbaTools + "'!Unmake", filePath, outputDir) 

当我打开任务pipe理器,我可以看到一个Excel进程仍在运行…如何杀死它,但干净的时候,工作完成? xl.Application.Run是否启动对macros的asynchronous调用? 在这种情况下,这可能会很棘手。

多谢你们 !! ;)

我不知道Python,但你需要使用:

 xl.Quit