How to run MS Access macro from python

I am trying to run an existing Microsoft Access macro using a python script. I currently have

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 an 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) 
+4
source share
1 answer

The start method expects the name of a "user-defined function or sub procedure". But if "test" is the name of the macro, use the RunMacro method

I'm not sure if parentheses are required, but one of them should work.

 objAccess.DoCmd.RunMacro 'test' objAccess.DoCmd.RunMacro('test') 
+5
source

Source: https://habr.com/ru/post/1395239/


All Articles