Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:使用win32com.client.dispatch打开工作簿将停用工作簿加载项_Python_Vba_Excel - Fatal编程技术网

Python:使用win32com.client.dispatch打开工作簿将停用工作簿加载项

Python:使用win32com.client.dispatch打开工作簿将停用工作簿加载项,python,vba,excel,Python,Vba,Excel,我正在尝试从Python运行Excel宏 我使用了这段代码: import os import win32com.client filepath = r"myfilepath" if os.path.exists(filepath): xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename=filepath) xl.Application.Run("SendReport")

我正在尝试从Python运行Excel宏

我使用了这段代码:

import os
import win32com.client

filepath = r"myfilepath"

if os.path.exists(filepath):
    xl=win32com.client.Dispatch("Excel.Application")
    xl.Workbooks.Open(Filename=filepath)
    xl.Application.Run("SendReport")
##    xl.Application.Save() # if you want to save then uncomment this line and change delete the ", ReadOnly=1" part from the open function.
    xl.Application.Quit() # Comment this out if your excel script closes
    del xl
代码工作正常,但我的工作簿使用外接程序中的自定义VBA函数。当我使用此分派方法打开工作簿时,外接程序将被停用,函数将不再工作

是否有其他方法可以打开工作簿,使外接程序保持活动状态?

我使用(如下)并且我的VBA代码+外部连接未被停用

import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')