我正在尝试从 python 脚本运行现有的 Microsoft Access 宏.我目前拥有的是
I'm trying to run an existing Microsoft Access Macro from a python script. What I currently have is
import win32api,time
from win32com.client import Dispatch
strDbName = 'Exit.mdb'
objAccess = Dispatch("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase(strDbName)
objDB = objAccess.CurrentDb()
objAccess.run('test')
objAccess.Application.Quit()
当我运行它时,我得到了错误
When I run this I get the error
Traceback (most recent call last):
File "accessmacro.py", line 10, in <module>
objAccess.run('test')
File "<COMObject Access.Application>", line 2, in run
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, u"Microsoft Office Access can't find the procedure 'test.'", None, -1, -2146825771), None)
运行方法 需要用户定义的函数或子过程"的名称.但是,如果 'test' 是宏的名称,请使用 RunMacro 方法
The Run Method expects the name of a "user-defined Function or Sub procedure". But, if 'test' is the name of a macro, use RunMacro Method
objAccess.DoCmd.RunMacro('test')
这篇关于如何从 python 运行 MS Access 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!