尝试通过Python运行Excel宏时,出现以下错误:Traceback (most recent call last):
File ".\test.py", line 17, in
xlApp.Application.Run(MACRO)
File ">", line 14, in Run
File "C:\Users\twauchop\Desktop\Python\virtual_envs\gutenberg\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Cannot run the macro 'test'. The macro may not be available in this workbook or all macros may be disabled.", 'xlmain11.chm', 0, -2146827284), None)
我尝试了other questions中建议的许多修复方法。在
我试了'xlApp.Application.Run(wb.name + "!" + MACRO)'。在
这是命名约定问题吗?我通过信任中心启用了所有功能,并将VBA sub更改为public。在
另外,我也不能从以编程方式打开的工作簿中运行宏(例如,如果我手动尝试)。但是,如果我手动打开工作簿,一切正常。在
我在64位系统Windows10上运行Python3.6.5。在
Python:
^{pr2}$
VBA:Public Sub test()
MsgBox "Hello World!"
End Sub