python vba 秒出结果_从Python运行VBA代码:宏可能被禁用

尝试通过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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值