在python中运行excelmacros并保存结果

我有两个文件,即“macro.xlms”和“data.csv”

我想从data.csv的macro.xmls文件运行macros[Analyze]来生成一些数据并保存结果

到目前为止,我的代码是:

macroPath="Macro.xlsm" filePath="Output.csv" def performAnalysis(): if os.path.exists(macroPath): excel = win32com.client.Dispatch("Excel.Application") excel.Visible= True excel.Workbooks.Add(filePath) excel.Application.Run(macroPath+"!Analyze") excel.Application.Quit() del excel else: print("Error") def main(): performAnalysis() main() 

当我运行上述我得到以下错误信息:

 pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Excel', u"Cannot run the macro 'C:\\Users\\Nabeel\\Desktop\\dense_breasts_experiments\\VolparaOutputExcelMacroOnly_Nov20thV1.xlsm!VolparaAnalyze'. The macro may not be available in this workbook or all macros may be disabled.", u'xlmain11.chm', 0, -2146827284), None) 

任何人都可以请指导我我做错了什么?

代码编辑:

 def performAnalysis(): if os.path.exists(macroPath): excel = win32com.client.Dispatch("Excel.Application") excel.Visible= True excel.Workbooks.Open(filePath) excel.Workbooks.Open(macroPath) excel.Application.Run(macroPath+"!Analyze") def main(): performAnalysis() main() 

仍然得到相同的错误