我正在尝试从Python运行宏。当从Access本身执行时,所说的宏工作得很好,但我尝试使用以下Python代码(很容易从How to run a MS Access macro from python中窃取):
from win32com.client import Dispatch
access_obj = Dispatch("Access.Application")
access_obj.Visible = False
access_obj.OpenCurrentDatabase("my_database_file.accdb")
access_obj.DoCmd.RunMacro("my_macro")
access_obj.DoCmd.CloseDatabase()
不幸的是,执行倒数第二行(...RunMacro("my_macro")
)会导致以下不透明错误消息:
com_error: (-2147352567, 'Exception occurred.', (0, None, 'You canceled the previous operation.', 'vbaac10.chm', 5738, -2146826287), None)
你知道这是什么意思吗?你知道吗
如果将宏命名为“AutoExec”,则当您打开数据库时,它将自动运行。你知道吗
资料来源:Create a macro that runs when you open a database
相关问题 更多 >
编程相关推荐